/*
PHOTOS-PEOPLE.CH - the site to be on...
*/

// Initialisation du namespace PP, Photos-People
var PP = new Object; 


// Pour Internet Explorer
if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}
	
/*
	Anciennes Fonctions Colorplaza
*/
/*
function AddImage(tn_url,image_url) {
  url = 'http://orders.colorplaza.com/cart/addimage.cpl?prid=' + cart_sid + '&imgurl=' + escape(image_url) + '&tnurl=' + escape(tn_url) + '&lang=FR&theme=cm';
  msgWin = window.open(url,'addPopup','toolbar=no,scrollbars=no,resizable=no,status=no,titlebar=no,width=200,height=160,screenX=300,screenY=300,top=300,left=300');
  if (cartWin != null) cartWin.location.href = cartUrl + '&refresh=1';
}

function ViewCart() {
  cartWin = window.open(cartUrl,'cartWindow','menubar=no,scrollbars=yes,status=no,width=795,height=560,screenX=300,screenY=300,top=300,left=300');
}

function FunCart() {
  cartWin = window.open(cartUrl+'&channel=1001','cartWindow','menubar=no,scrollbars=yes,status=no,width=795,height=560,screenX=300,screenY=300,top=300,left=300');
}
*/

var AddImage = function(imgID){
	$.get("/ajax/add_cart.php?r="+Math.random(), {
		"id_img":imgID
	}, function(data){
		if(window.cartWin) cartWin.location.reload(true);
		
		confirmationWin = window.open('', 'confirmationWindow', 
			'menubar=no,scrollbars=no,status=no,width=100,height=40');
		var _c = confirmationWin.document
		_c.write('<html><head><title>Image ajoutée</title></head><body><center style="font-family:sans-serif">' + 
			'<h3>Image ajoutée au panier !</h3>' +
			'</center></body></html>')
		hideConfirmationWin = setTimeout(function(){
			confirmationWin.close();
		},1000)
	});
	
	//alert("Votre image a bien été ajoutée au caddie.")
}
var ViewCart = function(){
	window.cartWin = window.open('/cart.php?lang='+lang+'&step=1', 
	//cartWin = window.open('http://www.photos-people.ch/cart.php?lang=fr&step=1', 
		'cartWindow','menubar=no,scrollbars=yes,status=no,width=800,height=600,screenX=300,screenY=300,top=300,left=300');
}
	
if(jQuery) (function(){
	
	$.extend($.fn, {
		
		rightClick: function(handler) {
			$(this).each( function() {
				$(this).mousedown( function(e) {
					var evt = e;
					$(this).mouseup( function() {
						$(this).unbind('mouseup');
						if( evt.button == 2 ) {
							handler( $(this) );
							return false;
						} else {
							return true;
						}
					});
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		
		rightMouseDown: function(handler) {
			$(this).each( function() {
				$(this).mousedown( function(e) {
					if( e.button == 2 ) {
						handler( $(this) );
						return false;
					} else {
						return true;
					}
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		
		rightMouseUp: function(handler) {
			$(this).each( function() {
				$(this).mouseup( function(e) {
					if( e.button == 2 ) {
						handler( $(this) );
						return false;
					} else {
						return true;
					}
				});
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		},
		
		noContext: function() {
			$(this).each( function() {
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		}
		
	});
	
})(jQuery);	


// Fonction à éxécuter quand le DOM est prêt
$(document).ready(function(){ 
	
	// Nombre de photos à afficher par page
	PP.photosPerPage=9;
	
	// Initialisation des variables d'action
	PP.dragging, PP.tagging, PP.farEnough, PP.writing=false; 
	
	// Désactive les liens qui ne renvoient pas sur une autre page
	$("a[href='#']").click(function(e){e.preventDefault();return false;});
	
	// Désactive la navigation au clavier quand l'utilisateur entre des données
	$("textarea, input").bind("focus", function(){PP.writing=true;}).bind("blur", function(){PP.writing=false;})
	
	// Sélectionne le texte du champ de recherche lorsqu'on clique dedans 
	$("#searchform .text").bind("focus", function(){ $(this).select(); });
	
	//	Raccourcis clavier/keycodes 27 : [ESC],  37 : [<-], 39 : [->]
	$(document).bind("keydown", function (e){
		if(!PP.writing) {
			if(e.keyCode == 37){PP.navigate(-1); e.preventDefault(); return false;}
			else if(e.keyCode==39){PP.navigate(1); e.preventDefault(); return false;}
		}
		if(e.keyCode == 27){ PP.cancelTagging()}
	});
	
	$(window).bind("unload", function(){
		if(cartWin) cartWin.close();
	})
	// Menu
	PP.slideUpMenu = function(what){
		what.children("ul").slideUp("fast", function(){
			what.children("a").removeClass("current");
		});
	};	
    $("#nav-one > li").mouseup(function(e){
		// Cacher le sous-menu
		if(this.visible){ 
			PP.slideUpMenu($(this)); 
			this.visible=false; 
			$(window).unbind("click.menu"); 
		}
		// Afficher le sous-menu
		else {
			PP.slideUpMenu($("#nav-one >li").not($(this)));
			$("#nav-one > li").not($(this)).each(function(){ this.visible=false; });
			$(this).children("ul").slideDown("fast");
			$(this).children("a").addClass("current");
			this.visible = true;
			$(window).bind("click.menu", function(){ 
				PP.slideUpMenu($("#nav-one >li").not($(this))); 
				$(window).unbind("click.menu"); 
				$("#nav-one > li").each(function(){ this.visible=false; }); 
			});
		}
		e.preventDefault();
		return false;
	});
	
	// Chatbox
	var refreshInterval = setInterval(function() { PP.reloadChatbox() }, 60000);
	PP.reloadChatbox = function(){
	$("#messages").empty();
	$.getJSON(path_website+"ajax/get_chatbox.php?r="+Math.random(),
	function(data) {
		$.each(data.message, function(i, item) {
			
			$("#messages").append("<div class='message'><b>"+item.chat_pseudo+"</b><br />"+item.chat_message+"<div class='date'>"+item.chat_date+"</div></div>");	
	})
	});
	};
	$("#add_message").click(function(){
	
	$.post(path_website+"ajax/add_chatbox.php", {
	chat_pseudo: $("#chat_pseudo").val(), 
	chat_message:$("#chatbox_message").val()}, function(){PP.reloadChatbox();});
		$("#chatbox_message").val('');
	})
	
	// Animation de chargement. Prend true/false comme paramètres
	PP.loading = function(s){ (s) ? $(".loading").stop().fadeIn("fast") : $(".loading").stop().fadeOut("slow"); }
	
	// Retour à l'affichage en miniatures
	$(".back_to_thumbnails").click(function(){
		if(Photos.length>1){
			window.location.hash = "#";
			PP.displayThumbnails(Math.ceil((PP.currentPhoto+1)/PP.photosPerPage)-1);		
		}
	});
		
		
	
	// Navigation, précédent/suivant
	$(".next").click(function(){PP.navigate(1)});
	$(".previous").click(function(){PP.navigate(-1)});
	
	$(".cancel_tagging").click(function(){PP.cancelTagging()});
	
	// Navigation dans les galeries
	PP.navigate = function(offset){
		PP.cancelTagging();
		if(PP.mode=='thumbnails'){				
			if(offset>0){
				if(PP.currentPage+offset < Math.ceil(Photos.length/PP.photosPerPage)){
					PP.currentPage = PP.currentPage+offset;
					PP.displayThumbnails(PP.currentPage)
				}
				else {offset--; PP.navigate(offset);}
			}
			else if(offset<0){
				if(PP.currentPage+offset >= 0){
					PP.currentPage = PP.currentPage+offset;
					PP.displayThumbnails(PP.currentPage);
				}
				else {offset++; PP.navigate(offset);}
			}
		}
		else if(PP.mode=='photo'){
			if(offset>0){
				if(PP.currentPhoto+offset<Photos.length){
					PP.currentPhoto = PP.currentPhoto+offset;
				}
				else { offset--; PP.navigate(offset);}
			}
			else if(offset<0){
				if(PP.currentPhoto+offset >= 0){
					PP.currentPhoto = PP.currentPhoto+offset;					
				}
				else {offset++; PP.navigate(offset);}
			}
		window.location.href="#"+(PP.currentPhoto+1)
		}
	}

	PP.displayPhoto=function(id){

		PP.currentPhoto=id;
		PP.currentPage = Math.ceil((PP.currentPhoto+1)/PP.photosPerPage)-1;
		
		(PP.currentPhoto>0) ? $(".previous").addClass("enabled") : $(".previous").removeClass("enabled");
		(PP.currentPhoto+1 < Photos.length) ? $(".next").addClass("enabled") : $(".next").removeClass("enabled");
	
		file = Photos[id].file;
		id_cat = Photos[id].id_cat;
		id_img = Photos[id].id_img;
		
		
		if($("#display_thumbnails").is(":visible")){
			$("#display_thumbnails:visible").slideUp("fast", function(){$(this).hide();  });
			PP.loading(0);
		}
		
		$("#display_photo, #tagged_users").show();
		$("#related_cat").hide()
		if(PP.friends)
			$("#tag_someone").show();
			
		var img = new Image();
		$(img)
			.load(function(){
				$("#photo, #commentaires, #tagged_users, #related_cat span").empty();
				$("#photo").append("<div class='wrap'></div>");
				
				$(this).noContext();
				$(this).appendTo("#photo .wrap");
				bestofpeople = window.location.href.search("bestofpeople");
				if(bestofpeople!=-1)
				{
				$.getJSON(path_website+"ajax/get_info_bestofpeople.php?lang="+lang+"&id_img="+Photos[id].id_img+"&r="+Math.random(),
			        function(data){
						if(data.info_bestofpeople)
							$("#get_info_bestofpeople").show().html(data.info_bestofpeople);
						//	$("#related_cat span").html("<a href='"+path_website+lang+"/gallery/images/"+Photos[id].id_cat+"'>"+data.cat_name+"</a>");
			        });
				
				}
				
				
				
				$("#photo .wrap").css({'left':(($("#photo").width()-$("#photo img").width())/2)+'px'});
				$(this).fadeTo("fast", 1.0)
				$("#pagination2").html("Photo <b class='no_photo'>N° "+(id+1)+"</b> sur "+ Photos.length+" <span class='gris' style='margin-left:20px'>ID: "+Photos[id].id_img+"</span>");
				if(show_cat_large == '1'){
				$("#related_cat").show()
					$.getJSON(path_website+"ajax/get_cat_name.php?id_cat="+Photos[id].id_cat+"&lang="+lang+"&r="+Math.random(),
			        function(data){
						if(data.cat_name)
							$("#related_cat span").html("<a href='"+path_website+lang+"/gallery/images/"+Photos[id].id_cat+"'>"+data.cat_name+"</a>");
			        });
				}
				else
					$("#related_cat span").hide()
				$(".add_bigimg_to_cart").unbind('click');
				$(".add_bigimg_to_cart").bind('click', function(e){

					// AddImage("http://www.photos-people.ch/stock/"+Photos[id].id_cat+"/small/"+Photos[id].file, 	
					// 						"http://www.photos-people.ch/stock/"+Photos[id].id_cat+"/hd/"+Photos[id].file); 
					AddImage(Photos[id].id_img);
					e.preventDefault();
					e.stopPropagation();
					return false;
				});
				$(".download_img_to_mobile").attr('href', urlmobile+"http://www.photos-people.ch/stock/"+Photos[id].id_cat+"/large/"+Photos[id].file)
				
				
				$.getJSON(""+path_website+"ajax/img_data_display.php?id_img="+Photos[id].id_img+"&lang="+lang+"&r="+Math.random(),
		        function(data){
					if(data.comments){
						$.each(data.comments, function(i, item) { 
						$("#commentaires").append("<div class='commentaire'><h5>"+item.auteur+"</h5> "+item.comment+"</div>");	
						})
					}

					if(data.tags){
					$.each(data.tags, function(i, item){
						$("#photo .wrap").append("<div class='tag' id='tag_"+i+"'>"+item.titre+"</div>");
						$("#tag_"+i).placeTag(item.x, item.y);
						$("#tagged_users").append("<a href='"+path_website+"index.php?lang="+lang+"&rub=members&id_member="+item.id_user+"'>"+item.titre+"</a>");						
						});
					}
					if(data.clics)
						$(".views").html(data.clics);
					if(data.iptc){
						$("#iptc").html(data.iptc);
					}	
					
		        });
				$(this).mousedown(function(e){
					PP.dragging=true;
					PP.draggedPhoto = path_website+"stock/"+id_cat+"/small/"+file;
					PP.draggedPhotoIdcat = id_cat;
					PP.draggedPhotoFile = file;
					PP.draggedPhotoIdImg = id_img;
					PP.startX=e.pageX;
					PP.startY=e.pageY;
					return false;
				})
				$(this).mouseup(function(e){
					if(!PP.farEnough && !PP.tagging)
						PP.navigate(1);
				});
			})
			.css("opacity", 0)
			.attr('src', ""+path_website+"stock/"+id_cat+"/large/"+file)	// #URL
			PP.mode='photo';
	}
	
	$.fn.placeTag = function(x, y){
		y=parseInt(y);
		x=parseInt(x);
		if(y+35 > $("#photo img").height())
			y = $("#photo img").height()-35
		if(y <15)
			y=15
		if(x - $(this).width()/2 < 0)
			x = $(this).width()/2
		if(x + 5 + $(this).width()/2 > $("#photo img").width())
			x = $("#photo img").width() - 5 - $(this).width()/2
		$(this).css({'top': Math.ceil(y+15) +'px', 'left':Math.ceil(x-$(this).width()/2)+'px'})
	}
	incremented = [];
	
	PP.displayThumbnails = function(page){
			if(Photos.length==1)
				window.location.hash = "#1";
			PP.currentPage = page;
			PP.loading(1);
			(page>0) ? $(".previous").addClass("enabled") : $(".previous").removeClass("enabled");	
			(page+1 < Math.ceil(Photos.length/PP.photosPerPage)) ? $(".next").addClass("enabled") : $(".next").removeClass("enabled");
			
			if($("#display_photo").is(":visible")){
				$("#display_photo:visible").slideUp("fast", function(){
					$("#photo").empty(); 
					$(this).hide(); 
				});
			}
			$("#display_thumbnails").show();
			
			$("#pagination").html("Bloc "+(page+1)+" sur "+Math.ceil(Photos.length/PP.photosPerPage) );
	
			$("#before, #after").empty();
			
			// HAHAH ! Si ça c'est pas moche… :D !
			
				if(PP.currentPage>0)
				$("#before").append("<a href='#'>1</a>")
				if(PP.currentPage-4>0)
				$("#before").append("<span>...</span> ")
				if(PP.currentPage-3>0)
				$("#before").append("<a href='#'>"+(PP.currentPage-2)+"</a>")
				if(PP.currentPage-2>0)
				$("#before").append("<a href='#'>"+(PP.currentPage-1)+"</a>")
				if(PP.currentPage-1>0)
				$("#before").append("<a href='#'>"+(PP.currentPage)+"</a>");
			
			
				numberOfPages=Math.ceil(Photos.length/PP.photosPerPage);
				
			
				if(numberOfPages-2>PP.currentPage)
					$("#after").append("<a href='#'>"+(PP.currentPage+2)+"</a>")
				if(numberOfPages-3>PP.currentPage)
					$("#after").append("<a href='#'>"+(PP.currentPage+3)+"</a>")
				if(numberOfPages-4>PP.currentPage)
					$("#after").append("<a href='#'>"+(PP.currentPage+4)+"</a>");
				if(numberOfPages-5>PP.currentPage)
					$("#after").append("<span>...</span> ")
				if(numberOfPages-1>PP.currentPage)
					$("#after").append("<a href='#'>"+numberOfPages+"</a>");
				
				$("#before a, #after a").click(function(){var page = parseInt($(this).text()); PP.displayThumbnails((page-1)); return false;})
				

			
			$("#display_thumbnails .thumbnails").empty();
			//var bestofpeople = window.location.href.search("bestofpeople");
			incrementThese = '';
			for(var i = page*PP.photosPerPage; i<page*PP.photosPerPage+PP.photosPerPage; i++){
				(function(){
					if(Photos[i]) {
					var img = new Image();
					var $i = i;
					if($i+1 == page*PP.photosPerPage+PP.photosPerPage){
						try
						{
						if(incremented.indexOf(Photos[$i].id_img) == '-1'){
							incremented.push(Photos[$i].id_img)
							incrementThese=incrementThese+Photos[$i].id_img;
						}
						}
						catch(err){
						if(window.console)
							console.log(err);
						}
						if(incrementThese.length>1 && window.location.href.search("debug") == '-1')
							$.get(path_website+"ajax/increment_counter_for.php?r="+Math.random(), {id_imgs:incrementThese});
						PP.loading(0);
					}
					else{
						try
						{
						if(incremented.indexOf(Photos[$i].id_img) == '-1'){
							incrementThese=incrementThese+Photos[$i].id_img+"-";
							incremented.push(Photos[$i].id_img);
						}
						}
						catch(err){
						if(window.console)
							console.log(err);
						}
						
	
					}
				//	if(bestofpeople!=-1)
				//		var where_to = "<a class='thumbnail' href='"+path_website+lang+"/gallery/images/"+Photos[i].id_cat+"'></a>";
				//	else
						var where_to = "<a class='thumbnail' href='#"+(i+1)+"'></a>";
					$(img)
						.load(function(){
							$(this).css({"margin-top": (160-this.height)/2+'px'})
							
							// Drag and drop
							$(this).parent("a").mousedown(function(e){
								PP.draggedPhoto = img.src;
						
								PP.draggedPhotoIdcat = Photos[$i].id_cat;
								PP.draggedPhotoFile = Photos[$i].file;
								PP.draggedPhotoIdImg = Photos[$i].id_img;
								PP.dragging=true;
								PP.startX=e.pageX;
								PP.startY=e.pageY;
								return false;
							})
							// AddImage("http://www.photos-people.ch/stock/"+PP.draggedPhotoIdcat+"/small/"+PP.draggedPhotoFile,"http://www.photos-people.ch/stock/"+PP.draggedPhotoIdcat+"/hd/"+PP.draggedPhotoFile); 
							param1 = "http://www.photos-people.ch/stock/"+Photos[$i].id_cat+"/small/"+Photos[$i].file;
							param2 = "http://www.photos-people.ch/stock/"+Photos[$i].id_cat+"/hd/"+Photos[$i].file;
							param3 = "http://www.photos-people.ch/stock/"+Photos[$i].id_cat+"/large/"+Photos[$i].file;
							imgID = Photos[$i].id_img;
							if(Photos[$i].id_cat != 2297)
							{
							$(this).parent("a").append("<a href='#add_to_cart' onclick='AddImage(\""+imgID+"\");return false;' class='add_to_cart'></a><a href='"
								+(urlmobile+param3)+"' class='mobile' target='_blank'></a>");
							}
							// <a href='$url_mobile$url_website/$path_folder_img/$id_cat/large/$file' target='_blank'>
							$(this).fadeTo("fast", 1.0)
						})
						.appendTo("#display_thumbnails .thumbnails")
						.wrap(where_to)
						.css("opacity", 0)
						.attr('src', ""+path_website+"stock/"+Photos[i].id_cat+"/small/"+Photos[i].file)
				}
			})();
			}
		PP.mode='thumbnails';
	}

	$(document).bind("mousemove", function(e){
		if(PP.dragging){
		if(!PP.farEnough){
			if(Math.sqrt(Math.pow((PP.startX-e.pageX),2)+Math.pow((PP.startY-e.pageY),2))>50){
				PP.farEnough=true;
				preview = new Image();
				$(preview)
					.attr("src", PP.draggedPhoto)
					.css({'position':'absolute', 'z-index':200, 'display':'none'})
					.appendTo("body")
					.slideDown("fast")	
			}
		}
		else {
			$(preview).css({'top':(e.pageY-(preview.height/2))+'px', 'left':(e.pageX-(preview.width/2))+'px'})
			
			if(($("#caddie").position().left+150) > e.pageX && e.pageX > $("#caddie").position().left && 
			$("#caddie").position().top < e.pageY && $("#caddie").position().top+100 > e.pageY){
	
				$("#caddie").css({'opacity':0.8})
				PP.addToCart=true;
			}
			else{
				$("#caddie").css({'opacity':0.5})
				PP.addToCart=false;
			}
		}
		}
		if (PP.tagging){
			$("#tag_prov").placeTag((e.pageX-$("#photo img").offset().left), (e.pageY-$("#photo img").offset().top));
		}
	})
		.bind("mouseup", function(){
		if(PP.dragging){
			PP.dragging=false;
			if(PP.farEnough)
				$(preview).slideUp("fast", function(){$(preview).remove();});
			if(PP.addToCart){
				$("#caddie").html("Photo ajoutée !<br />");
				// AddImage("http://www.photos-people.ch/stock/"+PP.draggedPhotoIdcat+"/small/"
				// 				+PP.draggedPhotoFile,"http://www.photos-people.ch/stock/"+PP.draggedPhotoIdcat+"/hd/"+PP.draggedPhotoFile); 
				// 				
				AddImage(PP.draggedPhotoIdImg);
				PP.addToCart=false;
				setTimeout(function(){$("#caddie").html("CADDIE"); $("#caddie").css({'opacity':0.5}); }, 1500)
			}
		}
		PP.farEnough=false;
		PP.dragging=false;
	});
	
	
	$("#add_comment").click(function(){
		$.post(path_website+"ajax/add_comments.php", { comments: $("#comment").val(), id_img:Photos[PP.currentPhoto].id_img, id_user:PP.id_user } );
	});
	
	PP.cancelTagging = function(){
		if(PP.tagging)
			$("#tag_someone").show("slow");
		$("#tag_helptext").hide("slow");
		$("#tag_prov").remove();
		PP.tagging=false;
		$("#photo img").css({'cursor':'default'})
	}
	
	

	// Tagging
	if(PP.friends){
	$("#tag_someone").hide();
	$("#which_user").bind("change", function(){
		$("#tag_someone").hide("slow");
		$("#tag_helptext").show("slow");
		PP.tagging=true;
		$("#photo img").css({'cursor':'crosshair'});
		opts = $("#which_user option")[this.selectedIndex];
		$("#photo .wrap").append("<div id='tag_prov' class='tag'>"+$(opts).text()+"</div>");
		$("#photo img").unbind("click");
		$("#photo img").click(function(e){
			$.post(""+path_website+"ajax/addtag.php", {
			id_user:$("#which_user").val(), id_tagger:PP.id_user, id_img:Photos[PP.currentPhoto].id_img, 
			coord_x:(e.pageX-$("#photo img").offset().left), 
			coord_y:(e.pageY-$("#photo img").offset().top)}, function(data) {alert(data); PP.displayPhoto(PP.currentPhoto); PP.cancelTagging(); });
		});
	});
	$("#which_user").append("<option value='"+PP.id_user+"'>Moi-même</option>");
	$.each(PP.friends, function(i){
		$("#which_user").append("<option value='"+PP.friends[i].id+"' title='"+PP.friends[i].nom+"'>"+PP.friends[i].nom+"</option>");
	});
	$("#which_user").append("<option>Tagguer une autre personne</option>");
	}

	
	jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
		}
	};

	
	// Affiche un message d'erreur si l'utilisateur a désactivé les cookies
	if(!$.cookie('test')){
		$.cookie('test', 'test');
		if(!$.cookie('test'))
			$("#cookie_warning").show();
	}
	
	PP.reloadChatbox();
	// Galerie photo
	if(typeof Photos == 'object' && Photos) {
		
		var anch = window.location.href.split("#")[1];
		
		var before = anch;
		/*
		if(!anch || isNaN(anch)){
			PP.displayThumbnails(0);
		}
		
		else {before=false;}
		*/
		var before = false;
		setInterval(function(){
			now = window.location.href.split("#")[1];
				if(before != now){
						if(!isNaN(now) && now != '' && now < (Photos.length+1))
							PP.displayPhoto((now-1));
						else if (now=='')
							PP.displayThumbnails(Math.ceil((PP.currentPhoto+1)/PP.photosPerPage)-1);
						else
							PP.displayThumbnails(0);
					}
			before = now;
		}, 200)
		
		PP.displayThumbnails(0);
	}
	
	
	// $("#most_clicked_bottom img").css({'bottom':(22+($(this).parent("div").height()-$("#most_clicked_bottom img").height())/2)+'px', 'left':(1)+'px'});
});

