/**
 * @author mica - michael@caillet.ch
 */
$(document).ready(function(){
	
	$('.categories a').hover(function(){
							  $(this).find('span').css({
							  				background:'#292929 url(themes/gentilcopain/img/bkg-search.png)'})
							 },
							 function(){
							 	 $(this).find('span').css({
							 				background:'none'})
							 })
	
	
	$('#homeCatList a').hover(function(){
		var src= $(this).find('img').attr('src').substr(0,$(this).find('img').attr('src').length-4);
		$(this).find('img').attr({'src':src+'_survol.jpg'});
						  },
					  function(){
						  	var src= $(this).find('img').attr('src').substr(0,$(this).find('img').attr('src').length-11);
							$(this).find('img').attr({'src':src+'.jpg'});
						  })
	
	function fade(item,eq,speed){
						var lengthItem=$(item).length;
	                    $(item).eq(eq).fadeIn(speed,function(){
	                    	if(eq<lengthItem){
	                    		fade(item,eq+1,speed);
	                    	}
	                    })
                    }
    

     if($.cookie('menu')!='ok')  { 
                    var date = new Date();
                    date.setTime(date.getTime() + (25 * 60 * 1000));
                    $.cookie('menu', 'ok', { path: '/', expires: date });
                    $('.categories').css({'height':$('.categories').height()+'px'});
                    $('#galleryRand a,.categories ul li a span').hide();
                    $('#blogextra').css({'marginTop':'-50px'}).animate({'marginTop':'0'},950,function(){fade('#galleryRand a',0,350),fade('.categories ul li a span',0,100);});
                     
                     
	}
	
	
	
	$('#search form').hide();
	$('#search').append('<a href="#">recherche</a>');
	$('#search a').css({'position':'relative','top':'-5px'}).click(function(){
		$(this).fadeOut(250,function(){
			$('#search form').fadeIn(250);
		});
		return false;
		
	})
	
	$('.icon').hover(function(){
							var src= $(this).find('img').attr('src').substr(0,$(this).find('img').attr('src').length-4);
							$(this).find('img').attr({'src':src+'O.png'});
						  },
					  function(){
						  	var src= $(this).find('img').attr('src').substr(0,$(this).find('img').attr('src').length-5);
							$(this).find('img').attr({'src':src+'.png'});
						  })
	$('.dc-category .post .read-it,.dc-search .post .read-it').hide();	
	$('.dc-category .post,.dc-search .post').hover(function(){
		if($(this).hasClass('selected')){
			$(this).css({'backgroundColor':'#444','backgroundImage':'url(themes/gentilcopain/img/selectedO.png)','backgroundRepeat':'no-repeat','backgroundPosition':'top right','cursor':'pointer'});
		}else{
			$(this).css({'background':'#444','cursor':'pointer'});
		}
	},function(){
		if($(this).hasClass('selected')){
			$(this).css({'background':'#363636','backgroundImage':'url(themes/gentilcopain/img/selected.png)','backgroundRepeat':'no-repeat','backgroundPosition':'top right'});
		}else{
			$(this).css({'background':'#363636 '});
		}
	})
	
	
	//
	
	$('.dc-category .post,.dc-search .post').click(function(){
		//alert($(this).find('.read-it a').attr('href'));
		window.location.href=($(this).find('.read-it a').attr('href'));
	})
	$('.dc-category .post a img,.dc-search .post a img').parent().click(function(){
		var href=$(this).parent().parent().parent().find('.read-it a').attr('href');
		$(this).attr({'href':href});
	})
	
	$('.dc-post .post .post-content a img,' +
	  '.dc-post .post .post-excerpt a img,' +
	  '.dc-category .post p a img,'+
	  '.dc-search .post p a img'
	  ).parent().css({
	  	'border':'6px solid #202020',
	  	'float':'left',
	  	'-moz-border-radius':'3px',
	  	'margin-right':'12px',
	  	'margin-bottom':'10px'
	  });
	  $('#gallery a img').parent().css({
	  	'border':'4px solid #202020',
	  	'float':'left',
	  	'-moz-border-radius':'3px'
	  })
	
	$('.dc-post .post a img,#gallery a img').each(function(){
		$(this).parent().attr({'rel':'groupe1'}).hover(
							function(){
								$(this).css({'border-color':'#444444'});
								$(this).find('img').css({'border-color':'#202020'});
							},
							function(){
								$(this).css({'border-color':'#202020'});
								$(this).find('img').css({'border-color':'#444444'});
							});
	
	});
	$('.dc-post .post a img,.dc-page .post a img,#galleryRand a img,#gallery a img').parent().fancybox();
	

	
	
	
	$('.submit').removeAttr('disabled');
	$('#footer a.icon,h1 a.icon').bstip({ hook:"top-mid",speed:10,color:'bstip'});
	$('a.tooltip').bstip({hook:"top-mid",speed:250,color:'bstip2'});
	$('.lastposts li.selected').bstip({hook:"mid-right",speed:10,color:'bstip'});
	
	
	if($.browser.msie && $.cookie('ie')!='ok') { 
		$( function() { 
			$('#iesucks p').html("Salut copain, il semble que tu surf avec internet explorer, ce navigateur ne respecte pas les normes du web et ouvre des portes aux logiciels malveillants. <br /><br /> Pour une meilleure experience de l'internet et une securite optimale, gentilcopain vous recommande d'utiliser des navigateurs recents, performants et securises a savoir: "); 
		});
	}else{
		$('#iesucks').hide();
	}
	
	$('#ieclose').click(function(){
		$('#iesucks').slideUp(250,function(){
			var date = new Date();
            date.setTime(date.getTime() + (25 * 60 * 1000));
            $.cookie('ie', 'ok', { path: '/', expires: date });
        });
		return false;
	});
	
	
	if($('#plan').is('div')){
			//http://maps.google.com/maps?
			//f=q&amp;
			//source=s_q&amp;
			//hl=fr&amp;geocode=
			//&amp;q=fribourg+switzerland&amp;
			//sll=46.730919,7.072449
			//&amp;
			//sspn=0.346394,0.892639&amp;
			//ie=UTF8&amp;ll=46.809636,7.155447&amp;spn=0.040127,0.11158&amp;z=14&amp;iwloc=addr&amp;output=embed&amp;s=AARTsJrrEKUOxuUf8Gt4sH8KutXZ-cXM9A"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=fr&amp;geocode=&amp;q=fribourg+switzerland&amp;sll=46.730919,7.072449&amp;sspn=0.346394,0.892639&amp;ie=UTF8&amp;ll=46.809636,7.155447&amp;spn=0.040127,0.11158&amp;z=14&amp;iwloc=addr" style="color:#0000FF;text-align:left">Agrandir le plan</a></small>
					$('.mail').attr({href:'mailto:lilo@gentilcopain.com'});
					$('.mail').html('lilo@gentilcopain.com');
					$('.geo').attr({'title':$('.geo').html()});
					$("#plan").css({'color':'#202020'}).googleMap(46.802586,7.150771, 7, {
						controls: ["GSmallMapControl", "GMapTypeControl"],
						markers: $(".geo")
					});
					
	}

	
});