$(document).ready(function(){
	$('#backRotare').cycle({timeout: 8000});
	
	//mainmenu
	$('#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(250, 1);
			}, function () {
				$img.stop().fadeTo(250, 0);
			});
		});
	
	/// bubble comming soon
	$("#bubble-en").css('opacity', 0);
		$("#soon-en").hover(function(){
			$("#bubble-en")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "-2px"},{ queue: false, duration:500});
		}, function(){
			$("#bubble-en").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
			
			
	$(function () {
			
		if($.browser.msie){
			var img = $("a:not(#logo) img");
		}else{
			var img = $("a img");
		}
		img.hover(function(){
			$(this).animate({ 
	        opacity: 0.5
	      }, 50 );
		},function(){
			$(this).animate({ 
	        opacity: 1
	      }, 50 );
		});
		
		
		$(".sf-menu").supersubs({
	        minWidth:    14,                                // minimum width of sub-menus in em units
	        maxWidth:    16,                                // maximum width of sub-menus in em units
	        extraWidth:  1                                  // extra width can ensure lines don't sometimes turn over
										 					// due to slight rounding differences and font-family
	    }).superfish({
	        delay:       1000,                               // delay on mouseout
	        animation:   {opacity:'show'/*,height:'show'*/}, // fade-in and slide-down animation
	        speed:       'fast',                             // faster animation speed
	        autoArrows:  false,                              // disable generation of arrow mark-up
	        dropShadows: false                               // disable drop shadows
	    });
	    
		

////////MediaSlider 

$('.social-link').hover(function(){
		$("#contactSlider", this).stop().animate({right:'0px'},{queue:false,duration:160});
	}, function() {
		$("#contactSlider", this).stop().animate({right:'-330px'},{queue:false,duration:160});
	});
	    
		
////////InputFocus 
		$('input[type="text"]').addClass("idleField");
			$('input[type="text"]').focus(function() {
				$(this).removeClass("idleField").addClass("focusField");
		    if (this.value == this.defaultValue){ 
		    	this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		});
		$('input[type="text"]').blur(function() {
			$(this).removeClass("focusField").addClass("idleField");
		    if ($.trim(this.value) == ''){
		    	this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});		
		
		
//////////

$('#topMenu').fadeIn("slow");
$('#searchForm').fadeIn("slow");
//$('textarea').prettyComments();


//////////Column
$('.wide').columnize({width:300});
$('#homeNews ul').find('li:last-child').css('background','none');

//////////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())+";path=/;domains=";
		}
		
		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 "";
		}
		

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

//////////Put some decoration on my links
		$("a[href$=pdf]").addClass("pdf").attr("target","_blank");
		$("a[href$=xls]").addClass("xls").attr("target","_blank");
		
//////////Tell me where i'm going
		$("a[rel='3m4il']").each(function(){
			var address = $(this).text();
			var server = $(this).attr('href');
			
			$(this).attr({
				href: 'mailto:'+ address +'@'+ server +'',
				rel: 'nofollow'
			});
			$(this).text(''+ address +'@'+ server +'');
		});
		
//////////Alternate
$('#accordion div.postCat').alternate();
$('div.postTitle').alternate();
$('#accordion div.postTitle .even h5').alternate();
$('#accordion div.postTitle .odd h5').alternate();
//////////Accordion
$("#accordion").accordion({ header: "h3" });
$(".postTitle").accordion({
            collapsible: true, active:0, header: "h5", autoHeight: true
});

$("#accordionContact").accordion({ header: "h3" });
//$(".postTitle").accordion({ header: "h5" });
/*
$("#accordion").accordion({
            active: 0, collapsible: false, header: "h3", autoHeight: false
        });
$(".postTitle").accordion({
            collapsible: true, active:0, header: "h5", autoHeight: false
        });
           
$('#accordion').accordion({
    active: false,
    collapsible: true            
});

$('.accordionPost').accordion({
    active: false,
    collapsible: true            
});  
*/


		
//////////Please help me J.J. Abrams i'm lost...
		if($("#siteMap").length !=0) {
			$("#siteMap").treeview({
				collapsed: false,
				animated: "medium",
				control:"#expandCollapse",
				persist: "location"
			});
		};

//////////Gmap
		if ($('#gmap').length != 0) {
				function initialize() {
					var latlng = new google.maps.LatLng(48.139058, -78.122406);
					var myOptions = {
						zoom: 16,
						center: latlng,
						noClear:false,
						mapTypeId: google.maps.MapTypeId.HYBRID,
						    mapTypeControl: true,
						    mapTypeControlOptions: {
						        style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
						        position: google.maps.ControlPosition.TOP_RIGHT
						    },
						navigationControl: true,
						navigationControlOptions: {
					        style: google.maps.NavigationControlStyle.SMALL,
					        position: google.maps.ControlPosition.LEFT
					    }
					};
					var map = new google.maps.Map(document.getElementById("gmap"), myOptions);
					
					var marker = new google.maps.Marker({
						position: latlng, 
						map: map
						
					
					});
				};
				initialize();
		};

			
	});	
});

