/* ------------------------------------------------------------------------
	General site settings
	Re-used througought the site
------------------------------------------------------------------------- */

var settings = {
	initialized : false,
	
	init : function(val) {
 		if (!this.initialized) {
			$.each(val, function(msg) {
				if (!settings[msg])
					settings[msg] = val[msg];
			});

			this.initialized = true;
		} else {
			return false;
		};
	}
};

defaultValues = {
	init : function() {
		var default_values = new Array();

	  $("input.default-value").focus(function() {
	    if (!default_values[this.id]) {
	      default_values[this.id] = this.value;
	    }
	    if (this.value == default_values[this.id]) {
	      this.value = '';
	    }
	    $(this).blur(function() {
	      if (this.value == '') {
	        this.value = default_values[this.id];
	      }
	    });
	  });
	}
}

var locale = {
    "en": {
        'click-to-vote': 'Click to vote',
        'including-your-vote': 'Including your vote',
        'error-first-name': 'Enter your first name.',
        'error-last-name': 'Enter your last name.',
        'error-city': 'Enter your city.',
        'error-postal-code': 'Enter your postal code.',
        'error-email': 'Enter your email address.',
        'error-invalid-email': 'Your email address is invalid. It must be in a "name@domain.com" format.',
        'error-photo': 'Submit a photo.',
        'error-invalid-photo': 'Your image is invalid. The image must be in a JPG, GIF or PNG format and must not exceed 4Mo.',
        'error-to-email' : 'Enter your friend\'s email address.',
        'error-invalid-to-email': 'Your friend\'s email address is invalid. It must be in a "name@domain.com" format.',
        'error-accepted': 'You must read and accept the conditions of use',
        'error-last-name': 'Enter your last name',
        'error-postal-code': 'Enter your postal code',
        'city-or-name': 'City or Name',
        'search-no-result': 'No photo meeting your criteria was found.'
    },
    "fr": {
        'click-to-vote': 'Cliquez pour voter',
        'including-your-vote': 'Incluant votre vote',
        'error-first-name': 'Veuillez entrer votre prénom.',
        'error-last-name': 'Veuillez entrer votre nom.',
        'error-city': 'Veuillez entrer votre ville.',
        'error-postal-code': 'Veuillez entrer votre code postal.',
        'error-email': 'Veuillez entrer votre courriel.',
        'error-invalid-email': 'Votre courriel est invalide. Il doit être de la forme "nom@domaine.com"',
        'error-photo': 'Veuillez soumettre une photo.',
        'error-invalid-photo': 'Votre image est invalide. L\'image doit être de format JPG, GIF ou PNG et d\'un poids maximum de 4Mo',
        'error-to-email' : 'Veuillez entrer le courriel de votre ami.',
        'error-invalid-to-email': 'Le courriel de votre ami est invalide. Il doit être de la forme « nom@domaine.com ».',
        'error-accepted': 'Veuilez confirmer avoir lu et accepté les Conditions d\'utilisation',
        'error-last-name': 'Veuillez entrer votre nom',
        'error-postal-code': 'Veuillez entrer votre code postal',
        'city-or-name': 'Ville ou Nom',
        'search-no-result': 'Aucune photo correspondant à vos critères n’a été trouvée.'
    }
};


var toggle_expand = 0;
var toggle_sender = 0;
var toggle_sender_thanks = 0;
var toggle_add = 0;
var toggle_buying = 0;
var toggle_conditions = 0;

var current_state = 'home_container';
var prev_state = '';

/*

home_container
sendtoafriend
addpictures


*/

$(document).ready(function() {
	$home_container = $('#home_container');
	initHeight = $home_container.height() + 'px';
	initWidth = $home_container.width() + 'px';
	
	
    // $('#main_center').height($(document).height());
	
	// Load home images 
	getImagesData();
	setRollover();
	
	// Home expander actions
	$('#expand_home').bind('click',function(){ return expandHome(); });
	$('.showmore').bind('click', function(){ return openLogoBox($(this).attr('href')); });

	// Pagination
	$('#prev_page').bind('click',function(){ return get_prev_page(); });
	$('#next_page').bind('click',function(){ return get_next_page(); });
	
	// Search
	$('form#search .submit').bind('click',function(){ return search(); });
	$('#search_string').bind('click',function(){ empty_search_string(); });
	$('#previous_search').bind('click',function(){ previous_search(); });
	
	// Blank logo footer action
	$('.logo_box .bt_close').bind('click', function(){
		$(this).parent('.logo_box').css('display','none');
		return false;
	});
	
	
	// Send to a friend sub container actions
	$('.bt_send').bind('click',function(){ return showSender(); });
	$('#sendtoafriend .close_box').bind('click', function(){ return showSender(); });

	// Send to a friend thanks closing actio
	$('#sendtoafriend-thanks .close_box').bind('click', function(){ return showSenderThanks(); });
	
	
	// Add picture sub container actions
	$('.addphoto').bind('click',function(){ return showAddpictures(); });
	$('#addpictures .close_box').bind('click', function(){ return showAddpictures(); });
	$('form#send_picture .bt_picture_submit').bind('click',function(){ $('form#send_picture').submit(); });
	
	// Add pictures custom checkboxes
	$('span.sweet_check').bind('click',function(){
		$(this).toggleClass('checked');
		if($(this).hasClass('checked')) 
			$(this).children('input:checkbox').attr('checked','checked');
		else
			$(this).children('input').removeAttr('checked');

	});
	
	
	
	
	// Conditions sub container actions
	$('.view_conditions').bind('click',function(){ return showConditions();	});
	$('#conditions .close_box').bind('click', function(){ return showConditions(); });
	
	
	
	// Buying sub container actions
	$('.bulbe').bind('click',function(){ return showBuying($(this).attr('href')); });
	$('.chanson').bind('click',function(){ return showBuying($(this).attr('href')); });
	$('#buying .close_box').bind('click', function(){ return showBuying(); });
	$('#buying .item .activate').bind('click',function(){ return checkedBuying($(this)); });
	$('form#sender .bt_send_submit').bind('click',function(){ $('form#sender').submit(); });
	
	
	
	// trigger submit action (buying section)
	$('#buying .bt_buying_submit').bind('click',function(){ 

		i = 1;
		if ($('#chanson').hasClass('checked')) {
			$('#item_name_1').val("Chanson");
			$('#quantity_1').val("1");
			if (!$('#song_amount').val())
				$('#song_amount').val("1");
			$('#amount_1').val($('#song_amount').val());
			i += 1;
		}
		if ($('#bulbe').hasClass('checked')) {
			$('#item_name_' + i).val("Bulbe");
			$('#quantity_' + i).val("1");
			if (!$('[name=bulbe_amount]:checked').val())
				$('[name=bulbe_amount]')[0].checked = true;
			$('#amount_' + i).val($('[name=bulbe_amount]:checked').val());
			i += 1;
		}
		if ($('#don').hasClass('checked')) {
			$('#item_name_' + i).val("Don");
			$('#quantity_' + i).val("1");
			if (!$('[name=don_amount]:checked').val())
				$('[name=don_amount]')[0].checked = true;
			if ($('[name=don_amount]:checked').val() == 'autre') {
				if (!$('#don_amount_other').val())
					$('#don_amount_other').val("20");
				amount = $('#don_amount_other').val();
			} else {
				amount = $('[name=don_amount]:checked').val();
			}
			$('#amount_' + i).val(amount);
		}

		$('form#buyingForm').submit(); }
	);
	$('#buying .item input').click(function(){ $(this).parents('.item').addClass('checked'); });
	

	$("#file_chooser").change(function(){
		$('input[name="decoy_text"]').val($(this).val());
	});


	$('a[rel=external]').attr('target','_blank');
	defaultValues.init();
	

	if (location.hash) {
		$("a[href*="+location.hash+"]:first").trigger('click');
	}
});




var checkedBuying = function(element){
	
	var wrapper_item = $(element).parent('.item').attr('id');
	
	if ($('#'+wrapper_item).hasClass('.checked'))
	{
		$('#'+wrapper_item +' input').each(function(){
			if ($(this).attr('type') == 'radio')
			{
				$(this).removeAttr('checked');
			}
			else
			{
				$(this).val('');
			}
		});
	}
	$('#'+wrapper_item).toggleClass('checked');
	return false;
}





/*----------------------------------*/
/*                                  
/*		Set Rollover 
/*		on images	
/*                                  
/*----------------------------------*/
var current_rating = 0;
var setRollover = function(){
	var rollovers = $('.rollover');
	$(rollovers).each(function(index, elt){
		// Set hover functions
		$(elt).children('.shadow').css('opacity','0');
		imgHover(elt);
		
		// Set star rating hover functions
		$(elt).find('ul.star-rating').hover(function() {
			current_rating = $(this).find('.current-rating').css('width');
			$(this).find('.current-rating').css('width','0');
		}, function() {
			$(this).find('.current-rating').css('width', current_rating);
		});
		
		// Set voting functions
		$(elt).find('ul.star-rating li').not('.current-rating').bind('click', function() {
			$.getJSON($(this).find('a').attr('href'), {}, function(data) {
			    photo_id = $(elt).find('ul.star-rating').data('photo_id');
				cookies.set('voted-'+photo_id, true);
				
				// Changing URLs and title attribute to reflect new vote
				$(elt).find('ul.star-rating li a').attr({'href': '#', 'title': locale[settings.lang]['including-your-vote']});
				
				// Changing the rating total, and deactivating the star highlighting on hover
				current_rating = (data.total_ratings / (data.votes*5) * 100) + '%';
				$(elt).find('ul.star-rating li.current-rating').css('width', current_rating);
                $(elt).find('ul.star-rating li').find('a').css({'width': current_rating, 'z-index': 1});
				
				$(elt).find('.vote').text(data.votes + ' vote' + (data.votes > 1 ? 's':''));
			});
			
			return false;
		});
	});	
}


/* Rollover images */
var imgHover = function(elt){
	$(elt).hover(
		function(){
			var that = this;
			$(that).children('.shadow').css('cursor','default').dequeue().animate({opacity:0.6},{duration:150});
			//$(that).children('.shadow').css('display','block');
			$(that).children('span').css('display','block');
			$(that).children('.star-rating').css('display','block');
		},
		function(){
			var that = this;
			$(that).children('span').css('display','none');
			$(that).children('.star-rating').css('display','none');
			//$(that).children('.shadow').css('display','none');
			$(that).children('.shadow').dequeue().animate({opacity:0},{duration:150});
		}
	);	
}







/*----------------------------------*/
/*                                  
/*		Expand container 
/*		to get more images	
/*                                  
/*----------------------------------*/

var expandHome = function(){
    reset_search();
	
	if (toggle_expand == 0)
	{
		prev_state = current_state;
		current_state = 'home_container';
		
		// expand to full size mode!
		$('.img_lister li').fadeOut('fast',function(){ $(this).empty(); });
		// Move footer
		$('#home_container').css('height', initHeight);
		$('#home_container .bottom .home_footer').hide().toggleClass('expand_footer');
		
		
		// Expand X
		$('#home_container').animate({width:'890px',height:'712px'},{duration:500,complete:function(){
			getImagesData();
			$('#home_container .bottom .img_lister').show();
			$('#home_container .footer').show();
		}});
		
		$('.bt_send').css('display','none');
		$('.bt_lang').css('display','none');
		
		$('#yellow_bar #blocs_wrapper').fadeOut('normal',function(){
			$(this).children('.bloc').hide();
			$(this).children('#bloc2').show();
			$(this).fadeIn('normal');
		});
		
		toggle_expand = 1;
	}
	else
	{
		// return to inital size mode!
		
		/* Clear images container */
		$('.img_lister li').fadeOut('fast',function(){ $(this).empty(); });
		
		$('#home_container').animate({width:initWidth,height:initHeight},{duration:500,complete:function(){
			/* Get home data */
			getImagesData();
			
			$('#home_container .footer').hide();
			$('#home_container .bottom .img_lister').hide();
			$('#home_container .bottom .home_footer').toggleClass('expand_footer').show();
			$('.bt_send').css('display','block');
			$('.bt_lang').css('display','block');
		}});
		
		
		
		$('#yellow_bar #blocs_wrapper').fadeOut('normal',function(){
			$(this).children('.bloc').hide();
			$(this).children('#bloc1').show();
			$(this).fadeIn('normal')
		});
		
		toggle_expand = 0;
	}
	$elHome = $('#expand_home');
	if ($elHome.hasClass("bt_more")) {
		$elHome.attr({'href': "#more"});
	} else {
		$elHome.attr({'href': "#"});
	};
	$elHome.toggleClass('bt_more').toggleClass('bt_less');
	
	// return false;
}





/*----------------------------------*/
/*                                  
/*		Ajax call
/*		Return json object  	
/*                                  
/*----------------------------------*/

var _page = 1;
var _search_key = null;
var empty_search_string = function() {
	if ($('#search_string').val() == 'Ville ou Nom' || $('#search_string').val() == "City or Name") {
		$('#search_string').val("");
	}
};

var reset_search = function() {
    if (window._search_key) {
        window._search_key = "";
        $("#search_string").val(locale[settings.lang]['city-or-name']);
    };
};

var get_next_page = function() {
	window._page += 1;
    $('.img_lister li').fadeOut('fast',function(){ $(this).empty(); });
	getImagesData();
	return false;
};

var get_prev_page = function() {
	window._page -= 1;
	$('.img_lister li').fadeOut('fast',function(){ $(this).empty(); });
	getImagesData();
	return false;
};

var search = function() {
	$('.img_lister li').fadeOut('fast',function(){ $(this).empty(); });
	window._search_key = $('#search_string').val();
	window._page = 1;
	getImagesData();
	return false;
};

var previous_search = function() {
	window._search_key = window._previous_key;
	$('#search_string').val(window._previous_key);
	window._page = 1;
	getImagesData();
	return false;
};

var _previous_key = '';
var getImagesData = function(){
    if (window._search_key == "Ville ou Nom" || window._search_key == "City or Name") {
        window._search_key = "";
    };
    
	$.ajax({
	  type: "GET",
	  url: "/mosaic/index/"+window._page+".json" + (window._search_key ? "?key=" + encodeURIComponent(window._search_key) : ''),
	  dataType: "json",
	  success: function(msg){
			i = 0;
			itemCount = 0;
			if (msg.length == 0) {
			    window._nb_photos = 0;
			    $("#search span.search-count").text(locale[settings.lang]['search-no-result']);
			    $('#pager').hide();
			    $('#previous_search').show();
			} else {
				$('.img_lister').empty()
				$('#pager').show();
				$("#search span.search-count").text(msg.length + ' photo' + (msg.length > 1 ? 's' : ''));
			        $('#previous_search').hide();
				window._previous_key = window._search_key;
			}

			$(msg).each(function(e){
				if (!$("#img_lister2").is(":visible")) {
					if (i > 9) { return; }
				};
				if (i > 15){
					div = '#img_lister2';
				}else{
					div = '#img_lister1';
				}
				
				if (itemCount == 16) itemCount = 0;
					
				rating = msg[e]['total_ratings'] == 0 ? 0 : msg[e]['total_ratings'] / (msg[e]['votes']*5) * 100;
				parse_url = true;
				vote_text = 'click-to-vote';
				if (cookies.get('voted-'+msg[e]['id'], '')) {
					parse_url = false;
					vote_text = 'including-your-vote';
				}
				
				$(div).append('<li class="item"><img src="'+msg[e]["img_src"]+'" alt="'+msg[e]["name"]+'" />'+
					'<div class="img_data rollover">'+
					'<span class="name">'+msg[e]["name"]+'</span>'+
					'<span class="city">'+msg[e]["city"]+'</span>'+
					'<span class="vote">'+msg[e]["votes"]+' vote'+(msg[e]['votes'] > 1 ? 's':'')+'</span>'+
						'<ul class="star-rating small-star">'+
							'<li class="current-rating" style="width:'+rating+'%;">&nbsp;</li>'+
							'<li><a href="'+(parse_url ? '/vote/'+msg[e]['id']+'/1.json' : '#')+'" title="'+locale[settings.lang][vote_text]+'" class="one-star">1</a></li>'+
							'<li><a href="'+(parse_url ? '/vote/'+msg[e]['id']+'/2.json' : '#')+'" title="'+locale[settings.lang][vote_text]+'" class="two-stars">2</a></li>'+
							'<li><a href="'+(parse_url ? '/vote/'+msg[e]['id']+'/3.json' : '#')+'" title="'+locale[settings.lang][vote_text]+'" class="three-stars">3</a></li>'+
							'<li><a href="'+(parse_url ? '/vote/'+msg[e]['id']+'/4.json' : '#')+'" title="'+locale[settings.lang][vote_text]+'" class="four-stars">4</a></li>'+
							'<li><a href="'+(parse_url ? '/vote/'+msg[e]['id']+'/5.json' : '#')+'" title="'+locale[settings.lang][vote_text]+'" class="five-stars">5</a></li>'+
						'</ul>'+
					'<div class="shadow"></div>'+
					'</div>'+
				'</li>');
				$(div).find('li.item:eq('+(itemCount)+')').css('opacity',0);
				$(div).find('li.item:eq('+(itemCount)+') img').css('opacity',1); // IE FIX
				
				if (i > 15){
					setTimeout("$('#img_lister2').find('li.item:eq("+itemCount+")').fadeTo('medium',1);",itemCount*50);
				}else{
					setTimeout("$('#img_lister1').find('li.item:eq("+itemCount+")').fadeTo('medium',1);",itemCount*50);
				}
				i += 1;
				itemCount++;
				
				if (cookies.get('voted-'+msg[e]['id'])) {
				    $("ul.star-rating:last li a").css({'width': rating+'%', 'z-index': 1});
				}
				
				// Set photo id on this ul.star-rating
				$("ul.star-rating:last").data('photo_id', msg[e]['id']);
				
			});
			setRollover();
			$('#photo_cursor').html(window._page);
			if (window._page == 1) {
				$('#prev_page').hide();
			} else {
				$('#prev_page').show();
			}

			if (window._nb_photos <= window._page * 32) {
				$('#next_page').hide();
			} else {
				$('#next_page').show();
			}

	  }
	});
}



/*----------------------------------*/
/*                                  
/*		Open logo box 	
/*                                  
/*----------------------------------*/

var openLogoBox = function(boxid){
	$(boxid).css('display','block');
	return false;
}


/*----------------------------------*/
/*                                  
/*		Show send to a friend form
/*                                  
/*----------------------------------*/

var showSender = function(){
	
	
	
	if (toggle_sender == 0)
	{
		prev_state = current_state;
		current_state = 'sendtoafriend';
		
		if (prev_state == 'addpictures' || prev_state == 'buying' || prev_state == 'conditions') {
			toggle_add = 0;
			toggle_buying = 0;
			toggle_conditions = 0;
		}
		
		$('.bt_send').css('opacity',1).animate({opacity:0},{duration:250,complete:function(){$(this).css('display','none')}});
	

		$('#'+prev_state).fadeOut('normal',function(){
			$(this).css('display','none');
			$('#yellow_bar #blocs_wrapper').css('display','none');
			$('#'+current_state).fadeIn();
		});

		toggle_sender = 1;
	}
	else
	{
		$('.bt_send').css('opacity',0).animate({opacity:1},{duration:250,complete:function(){$(this).css('display','block')}});

		closeSubContainer();
		
		toggle_sender = 0;
	}
	
	// return false;
}

var showSenderThanks = function() {
	if (toggle_sender_thanks == 0)
	{
		prev_state = current_state;
		current_state = 'sendtoafriend-thanks';
		
		$('#'+prev_state).fadeOut('normal',function(){
			$(this).css('display','none');
			$('#yellow_bar #blocs_wrapper').css('display','none');
			$('#'+current_state).fadeIn();
		});

		toggle_sender_thanks = 1;
	}
	else
	{
		closeSubContainer();
		
		toggle_sender_thanks = 0;
	}
	
	return false;
}


/*----------------------------------*/
/*                                  
/*		Show add picture form
/*                                  
/*----------------------------------*/

var showAddpictures = function(){
	
	if (toggle_add == 0)
	{
		prev_state = current_state;
		current_state = 'addpictures';
		
		$('#'+prev_state).fadeOut('normal',function(){
			$(this).css('display','none');
			$('#yellow_bar #blocs_wrapper').css('display','none');
			$('#'+current_state).fadeIn();
		});

		toggle_add = 1;
	}
	else
	{		

		closeSubContainer('home_container');
		
		toggle_add = 0;
	}
	
	// return false;
}




/*----------------------------------*/
/*                                  
/*		Show conditions
/*                                  
/*----------------------------------*/

var showConditions = function(){
	
	if (toggle_conditions == 0)
	{
		prev_state = current_state;
		current_state = 'conditions';
		
		if (prev_state == 'addpictures') {
			toggle_add = 0;
		}
		
		$('#'+prev_state).fadeOut('normal',function(){
			$(this).css('display','none');
			$('#yellow_bar #blocs_wrapper').css('display','none');
			$('#'+current_state).fadeIn();
		});

		toggle_conditions = 1;
	}
	else
	{		

		closeSubContainer('addpictures');
		toggle_add = 1;
		
		toggle_conditions = 0;
	}
	
	return false;
}



var closeSubContainer = function(return_to){
	prev_state = current_state;
	current_state = (''+return_to == 'undefined') ? 'home_container' : return_to;
	
	$('#'+prev_state).fadeOut('normal',function(){
		$('#'+current_state+' .item img').css({display:'block'})
		$('#'+current_state).fadeIn('fast');
		
		$('#yellow_bar #blocs_wrapper').css('display','block');
	});
}










/*----------------------------------*/
/*                                  
/*		Show buying form
/*                                  
/*----------------------------------*/

var showBuying = function(activeItem){
	
	if (toggle_buying == 0)
	{
		prev_state = current_state;
		current_state = 'buying';
		
		orderBuyingItems(activeItem);
		
		$('.bt_send').css('z-index','4');
		$('.bt_lang').css('z-index','4');
		$('#'+prev_state).fadeOut('normal',function(){
			$(this).css('display','none');
			$('#yellow_bar #blocs_wrapper').css('display','none');
			$('#'+current_state).fadeIn();
		});
		
		toggle_buying = 1;
	}
	else
	{
		
		closeSubContainer();
		$('.bt_send').css('z-index','1');
		$('.bt_lang').css('z-index','1');
		toggle_buying = 0;
	}
	// return false;
}


// Form init functions
var sender = {
    init: function() {
        // Form validation
    	$('#sender').validate({
    		errorPlacement: function(error, element) {
      		    $(error).insertAfter($(element).parent('.input_wrapper'));
    		},
    		messages: {
    		    "data[From][name]": locale[settings.lang]['error-first-name'],
    		    "data[From][email]": {
    		        required: locale[settings.lang]['error-email'],
    		        email: locale[settings.lang]['error-invalid-email']
    		    },
    		    "data[To][email]": {
    		        required: locale[settings.lang]['error-to-email'],
    		        email: locale[settings.lang]['error-invalid-to-email']
    		    }
    		},
    		submitHandler: sender.submit
    	});
    },
    submit: function() {
		var params = {}; 
		inputs = $("#sender").find("input[type='text'], input[type='textarea'], input[type='hidden'], input[type='submit'], option[selected], input[checked], textarea");
 		inputs.each(function() { 
			params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value; 
		});

		var rand_no = Math.random();
		
		$.ajax({
			type:"POST",
			url:"/friend/send/?rand=" + rand_no,
			data : params,
			dataType: "json",
			timeout: 20000,
			success: function(errors) {
			    return showSenderThanks();
			}
	
		});
		
		return false;

        
    }
}

var send_picture = {
    init: function() {
        $('#send_picture').validate({
    		errorPlacement: function(error, element) {
    		    if ($(element).attr('name') == 'data[File][image]') {
          		    $(error).insertAfter($(element).parent().parent().find('.input_wrapper'));
          		} else if($(element).attr('name') == 'data[Photo][has_accepted]') {
          		    $(element).parent().parent().append($(error));
    		    } else {
          		    $(error).insertAfter($(element).parent('.input_wrapper'));
    		    }
    		},
    		rules: {
    		  "data[File][image]": {
    		      required: true,
    		      accept: "png|jpe?g|gif"
    		  }
    		},
    		messages: {
    		    "data[Photo][first_name]": locale[settings.lang]['error-first-name'],
    		    "data[Photo][last_name]": locale[settings.lang]['error-last-name'],
    		    "data[Photo][postal_code]": locale[settings.lang]['error-postal-code'],
    		    "data[Photo][city]": locale[settings.lang]['error-city'],
    		    "data[Photo][email]": {
    		        required: locale[settings.lang]['error-email'],
    		        email: locale[settings.lang]['error-invalid-email']
    		    },
    		    "data[File][image]": {
    		        required: locale[settings.lang]['error-photo'],
    		        accept: locale[settings.lang]['error-invalid-photo']
    		    },
    		    "data[Photo][has_accepted]" : locale[settings.lang]['error-accepted']
    		    
    		}
    	});
    }
}



/*----------------------------------*/
/*                                  
/*		Ordering buying items
/*                                  
/*----------------------------------*/
var orderBuyingItems = function(item){

	switch(item)
	{  
	case '#bulbe':
	  $('#bulbe').animate({top:'0px'}).addClass('active').addClass('checked');
	  $('#chanson').animate({top:'258'}).removeClass('active').removeClass('checked');
	  $('#don').animate({top:'473px'}).removeClass('active').removeClass('checked');
		break;
	case '#chanson':
	  $('#chanson').animate({top:'0'}).addClass('active').addClass('checked');
	  $('#bulbe').animate({top:'215px'}).removeClass('active').removeClass('checked');
	  $('#don').animate({top:'473px'}).removeClass('active').removeClass('checked');
	  break;  
	case '#don':
	  $('#don').animate({top:'0'}).addClass('active').addClass('checked');
	  $('#bulbe').animate({top:'120px'}).removeClass('active').removeClass('checked');
	  $('#chanson').animate({top:'378px'}).removeClass('active').removeClass('checked');
	  break; 
	default:
	  $('#bulbe').animate({top:'0'}).addClass('active').addClass('checked');
	  $('#chanson').animate({top:'258px'}).removeClass('active').removeClass('checked');
	  $('#don').animate({top:'473px'}).removeClass('active').removeClass('checked');
	}

	return false;
}

// Cookie stuff
var cookies = {
	set : function(id, value) {
	    document.cookie = id+'='+value+';path=/;expires='+this.time(365);		
	},
	get : function(id, default_value) {
	    var re          = new RegExp(id+'=(.*)');
	    var value       = re.exec(document.cookie);
	    return (value) ? value[1].split(';')[0] : default_value;
	},
	time : function(days) {
	  var now = new Date();
	  var exp = new Date();
	  var x   = Date.parse(now) + days*24*60*60*1000;

	  exp.setTime(x);
	  str = exp.toUTCString();
	  re = '/(\d\d)\s(\w\w\w)\s\d\d(\d\d))/';
	  return str.replace(re,"$1-$2-$3");
	}
};

/* ------------------------------------------------------------------------
	Used for the music player
------------------------------------------------------------------------- */

	var musicPlayer = {
		toggle : function(caller){
			if($(caller).hasClass('play')){
				player.sendEvent('PLAY');
				$(caller).removeClass('play').addClass('stop');
			}else{
				player.sendEvent('STOP');
				$(caller).removeClass('stop').addClass('play');
			}
		}
	}
