$(document).ready(function()
	{
	$(function () {
			
		
//////////When you pass over me, I'm shining like the sun
		$('#mainMenu li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(350, 1);
			}, function () {
				$img.stop().fadeTo(750, 0);
			});
		});
		
		$('#directionMenu li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(350, 1);
			}, function () {
				$img.stop().fadeTo(250, 0);
			});
		});		
	
		
//////////The last one doesn't get a piece of cake
		$("#footer .menu").find("li:last").each(function(){
			$(this).css({"background":"none"});
		});
		$("#footer .menu").find("li:first").each(function(){
			$(this).css({"padding":"0 10px 0 0"});
		});
		
//////////When you look at me ... I completely disappear
		$("#top").find("input").each(function(){
			$(this).focus(function () {
				$(this).val("");
			});
		});
		

//////////Cookie monster just around the corner
		function setCookie(name,value,expiredays){
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
		}
		
		function getCookie(c_name){
			if (document.cookie.length>0){
			  c_start=document.cookie.indexOf(c_name + "=");
				  if (c_start!=-1){ 
				    c_start=c_start + c_name.length+1; 
				    c_end=document.cookie.indexOf(";",c_start);
				    if (c_end==-1) c_end=document.cookie.length;
				    return unescape(document.cookie.substring(c_start,c_end));
			    } 
			}
		return "";
		}
		
		function checkCookie(c_name){
			getSizeCookie=getCookie(c_name);
			if (getSizeCookie!=null && getSizeCookie!=""){
				alert('The number is '+getSizeCookie+'!');
				}
			else{
				size=prompt('Please enter a number:',"");
					if (size!=null && size!=""){
						setCookie('textSize',size,365);
					}
			}
		}

	//checkCookie();
	
	
//////////Make me bigger or smaller, I don't care		
		// Original Font Size
		var originalFontSize = $('html').css('font-size');
			$("#normal").click(function(){
				$('html').css('font-size', originalFontSize);
				setCookie('textSize',""+ originalFontSize + "",365);
		});
		
		var getSizeCookie = getCookie("textSize");
		if(getSizeCookie!=null && getSizeCookie!=""){
			var getSizeCookieNum = parseFloat(getSizeCookie, 10);
			$('html').css('font-size', getSizeCookieNum);
		};
		
		// Increase Font Size
		$("#plus").click(function(){
			var currentFontSize = $('html').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('html').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});
		// Decrease Font Size
		$("#minus").click(function(){
			var currentFontSize = $('html').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('html').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});

		
		
//////////Little bubble falling from the sky
		$("#bubble").css('opacity', 0);
		$("#soon").hover(function(){
			$("#bubble")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "0px"},{ queue: false, duration:500});
		}, function(){
			$("#bubble").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
		
		
//////////The french connection
		$("#connexion").each(function(){
			// options
			var hideDelay = 500;
			var hideDelayTimer = null;
		
			// tracker
			var beingShown = false;
			var shown = false;
			
			$("#connexion,#connectMe")
			.mouseover(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (beingShown || shown) {
				return;
				} else {
				beingShown = true;
				
				$("#connectMe")
				.css({
					display: "block"
				})
				.animate({ 
					opacity:1,
					top:0
				},500, "swing", function() {
		          beingShown = false;
		          shown = true;
		        });
		        }
			}).mouseout(function(){
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					$("#connectMe")
					.animate({ 
						opacity:0,
						top:-45
					}, 500, 'swing', function () {
					shown = false;
					$("#connectMe").css('display', 'none');
					});
					}, hideDelay);
			});
		});

		
//////////Print me me me...
		$("#print").click(function(){
			window.print();
		});
		
		

/////////She's The Form, you have to do what she say...
		$(".post").find(":text").each(function(){
			$(this).addClass("text");
		});
		$(".post").find(":password").each(function(){
			$(this).addClass("password");
		});
		$(".post").find(":checkbox").each(function(){
			$(this).addClass("checkbox");
		});
		$(".post").find(":submit").each(function(){
			$(this).addClass("submit");
		});
		$(".post").find(":button").each(function(){
			$(this).addClass("submit");
		});
				

		
//////////Picasso would have been proud...
		$(".gallery a").lightBox();
		
		
		
		
//////////Flash Gordon resizing
		var banniereControlOne = '-on';
		var banniereControlTwo = '';
		var banniereSize = '300px';
		var banniereResize = '100px';
		var banniereGiveCookieOne = 'small';
		var banniereGiveCookieTwo = 'big';
		
		var banniereCookie = getCookie('banniere');
		if(banniereCookie == 'small'){
			var banniereControlOne = '';
			var banniereControlTwo = '-on';
			var banniereSize = '100px';
			var banniereResize = '300px';
			var banniereGiveCookieOne = 'big';
			var banniereGiveCookieTwo = 'small';
			$('#control').attr( "src", "/wp-content/themes/sri/images/control-flash"+ banniereControlTwo +".png");
			$('#controlOver').attr(	"src", "/wp-content/themes/sri/images/control-flash"+ banniereControlTwo +"-over.png");
			$(".banniere, #banniere").css('height', banniereSize);
			setCookie('banniere',banniereGiveCookieTwo,365);
			
		};
		//alert(banniereCookie);
		$("#controller").toggle(
			function(){
				$('#control').attr( "src", "/wp-content/themes/sri/images/control-flash"+ banniereControlOne +".png");
				$('#controlOver').attr(	"src", "/wp-content/themes/sri/images/control-flash"+ banniereControlOne +"-over.png");
				$(".banniere, #banniere").animate( {height: banniereResize}, 500 );
				setCookie('banniere',banniereGiveCookieOne,365);	
			},
			function(){
				$('#control').attr( "src", "/wp-content/themes/sri/images/control-flash"+ banniereControlTwo +".png");
				$('#controlOver').attr("src", "/wp-content/themes/sri/images/control-flash"+ banniereControlTwo +"-over.png");
				$(".banniere , #banniere").animate( {height: banniereSize} , 500 );
				setCookie('banniere',banniereGiveCookieTwo,365);	
			}
		); 
		if ( $.browser.msie && $.browser.version == 6.0){
		}else{
			var cssObj = {
			'opacity': '0',
			'display': 'block'
			};
			$('#controlOver').css(cssObj);
			$('#controller').hover(function () {
				$('#controlOver').stop().fadeTo(350, 0.85);
			}, function () {
				$('#controlOver').stop().fadeTo(750, 0);
			});
		}
			

//////////google maps
		function gmaps() {
			if(document.getElementById("map")!= null){
				var map = new GMap2(document.getElementById("map"));

				var latlng = new GLatLng(45.462298, -73.817096);
				map.setCenter(latlng, 15);
				map.addOverlay(new GMarker(latlng));
				map.openInfoWindowHtml( latlng , '<strong>Sérigraphie Richford</strong><br>111 Avenue Manfred<br>Pointe-Claire, Québec<br>H9R 4Y4');
			}
		}
		gmaps();
		
	});	
});







