$(document).ready(function(){
  // Your code here...
  
  //////////Rollover & Swap
		$('#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(450, 0);
			});
		});	

	////////////////////////
	$("#mainMenu ul ul ").css('opacity', 0);
	$("#mainMenu ul ul ").css({display: "none"}); // Opera Fix
	$("#mainMenu li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none", "z-index":9999}).animate({ 
			"height": "toggle",
			opacity: 1      
		  }, 300 );
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"}).animate({ 
			"height": "toggle",
			opacity: 0      
		  }, 200 );
			});
	$('#printing 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(250, 1);
			}, function () {
				$img.stop().fadeTo(350, 0);
			});
		});	
	
	$('.toppage').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(250, 1);
			}, function () {
				$img.stop().fadeTo(350, 0);
			});
		});	
	$('.imgbtn').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(250, 1);
			}, function () {
				$img.stop().fadeTo(350, 0);
			});
		});	
							
	//////////Print me me me...
		$("#print").click(function(){
			window.print();
		});


	

//if ($('.ulfade').length !=0) {
	$('.ulfade').cycle({
		speed:500,
		cleartype: 0,
		pause:1,
		next:'#next', 
		prev:'#prev' 
	});
//};

//if ($('.ulfade').length !=0) {
	$('.ulfadeComm').cycle({
		speed:500,
		cleartype: 0,
		pause:1
	});
//};

//if ($('.ulfade').length !=0) {
	$('.ulfadeCommNav').cycle({
		speed:500,
		cleartype: 0,
		pause:1
	});
//};
			

//////////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 = $('#postcontent').css('font-size');
		//	alert(originalFontSize);
		if ($.browser.msie) {
			var originalFontSize = parseInt(originalFontSize, 10);
			//var originalFontSize = originalFontSize-1;
		//	alert(originalFontSize);
		}
		$("#normal").click(function(){
			$('#postcontent').css('font-size', originalFontSize);
			setCookie('textSize',""+ originalFontSize + "",365);
		});
		
		var getSizeCookie = getCookie("textSize");
		if(getSizeCookie!=null && getSizeCookie!=""){
			var getSizeCookieNum = parseInt(getSizeCookie, 10);
		//	alert(getSizeCookieNum);
			$('#postcontent').css('font-size', getSizeCookieNum);
		};
		
		// Increase Font Size
		$("#plus").click(function(){
			var currentFontSize = $('#postcontent').css('font-size');
			var currentFontSizeNum = parseInt(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*1.2;
			$('#postcontent').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});
		// Decrease Font Size
		$("#minus").click(function(){
			var currentFontSize = $('#postcontent').css('font-size');
			var currentFontSizeNum = parseInt(currentFontSize, 10);
			var newFontSize = currentFontSizeNum*0.8;
			$('#postcontent').css('font-size', newFontSize);
			setCookie('textSize',""+ newFontSize + "",365);
			return false;
		});		

			
	//////////Little bubble falling from the sky
		$("#bubble-fr").css('opacity', 0);
		$("#soon-fr").hover(function(){
			$("#bubble-fr")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "0px"},{ queue: false, duration:500});
		}, function(){
			$("#bubble-fr").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
		
		
		$("#bubble-en").css('opacity', 0);
		$("#soon-en").hover(function(){
			$("#bubble-en")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "0px"},{ queue: false, duration:500});
		}, function(){
			$("#bubble-en").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
		
//////////Tell me where i'm going
		$("a[rel='3m4il']").each(function(){
			var spaceShip = $(this).text();
			var spaceStation = $(this).attr('href');
			
			$(this).attr({
				href: 'mailto:'+ spaceShip +'@'+ spaceStation +'',
				rel: 'nofollow'
			});
			$(this).text(''+ spaceShip +'@'+ spaceStation +'');
		});
		
		
  
});