// -------------------------------------------------------------------------------------------
// Scroll 
// ------------------------------------------------------------------------------------------- 	
$(window).load(function() {
	try{mCustomScrollbars();}catch(e){}
});
function mCustomScrollbars(){
	$("#mcs_container").mCustomScrollbar("vertical",500,"easeOutCirc",1,"auto","yes","yes",10); 
	$("#mcs2_container").mCustomScrollbar("vertical",500,"easeOutCirc",1,"auto","yes","yes",10); 
}
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}
function LoadNewContent(id,file){
	$("#"+id+" .customScrollBox .content").load(file,function(){
		try{
			mCustomScrollbars();
		}catch(e){}
	});
}


// -------------------------------------------------------------------------------------------
// Primary Navigation
// ------------------------------------------------------------------------------------------- 	
$(document).ready(function(){
	$('nav a').attr('title','');
	$('nav a').click(function(){
		var thisClass = $(this).attr('class');
		if(thisClass != "active"){
			$('nav a').removeClass('active');
			$(this).addClass('active');
		}
	});	
});
$(document).ready(function(){
	$('nav a').each(function(){
		if($(this).attr('href') == window.location.hash){
			$('nav a').removeClass('active');
			$(this).addClass('active');
		}
		if(window.location.hash == ""){
			$('nav a:first').addClass('active');
		}
	});
});


// -------------------------------------------------------------------------------------------
// Vertical Align
// ------------------------------------------------------------------------------------------- 	
$(document).ready(function(){
	var newMargin = ($(document).height() - $('#container').height()) *0.4;
	if(newMargin>0){
		$('#container').css({'margin-top':newMargin});
	}else{
		$('#container').css({'margin-top':'20px'});
	}
});


// -------------------------------------------------------------------------------------------
// Load Page
// ------------------------------------------------------------------------------------------- 	
setTimeout( function() { 
	$('#container').css({
		opacity: 0, 
		display: 'block', 
		visibility: 'visible'
	}).animate({
		opacity: 1
	}, 1000, function() {
		$('header').css({
			opacity: 0, 
			display: 'block', 
			visibility: 'visible'
		}).animate({
			opacity: 1
		}, 500, function() {
			$('nav').css({
				opacity: 0, 
				display: 'block', 
				visibility: 'visible'
			}).animate({
				opacity: 1
			}, 500, function() {
				$('#main').addClass('preloader');
			});				
		});		
	});
}, 500);


// -------------------------------------------------------------------------------------------
// Ajax
// ------------------------------------------------------------------------------------------- 	
$(document).ready(function(){	
	$('nav a').click(function (){			
		checkURL(this.hash,"menu");		
	});		
	vault = $('#content').html();			
	setInterval("checkURL(hash='','check')",250);		
});

var lasturl = "";

function checkURL(hash,clickevent){	
	if(!hash){
		hash = window.location.hash;
	} 	
	if(hash != lasturl){
		lasturl = hash;	
		if(hash==""){		
			$('#content').html(vault);			
		}		
		if(hash!=""){	
			hash=hash.replace('#!/',''); 		
			loadPage(hash,clickevent);
		}		
	}			
	$('.flags .pt').attr('href','http://www.geowinds.com/'+window.location.hash+'');	
	$('.flags .uk').attr('href','http://www.geowinds.com/uk/'+window.location.hash+'');	
}

loadPage("home","init");

function loadPage(url,clickevent){	
	$.ajax({
		url: "pages/"+url+".html", dataType: "html", success: function(msg){
			if(parseInt(msg)!=0){					
				if(clickevent == "init"){					
					$('#content').html(msg);									
				}	
				else{	
					$('#content').animate({ opacity: 0 }, 400, function() { 
						$('#content').html(msg).css({opacity: 0, display: 'block', visibility: 'visible'});
						setTimeout(function(){ 
							$('#content').css({opacity: 0, display: 'block', visibility: 'visible'}).animate({ opacity: 1 }, 400, function() {
								$('#article').css({opacity: 0, display: 'block', visibility: 'visible'}).animate({ opacity: 1 }, 400); 
								try{
									mCustomScrollbars();
								}catch(e){}
							}); 
						}, 400);
					});
				}
			}
		}
	});
}



// -------------------------------------------------------------------------------------------
// Calendar
// ------------------------------------------------------------------------------------------- 					   
var meses = new Array(12);
meses[0] = "Janeiro";
meses[1] = "Fevereiro";
meses[2] = "Março";
meses[3] = "Abril";
meses[4] = "Maio";
meses[5] = "Junho";
meses[6] = "Julho";
meses[7] = "Agosto";
meses[8] = "Setembro";
meses[9] = "Outubro";
meses[10] = "Novembro";
meses[11] = "Dezembro";
var data = new Date();
var dia = data.getDate();
var mes = data.getMonth();
var ano = data.getFullYear();
var mins = data.getMinutes();
var sec = data.getSeconds();
var hrs = data.getHours();

var _data = meses[mes] + " " + dia + ", " + ano;
$('span#date').append(_data + '<span class="separator">|</span>').show();

if (mins < 10){ mins = "0" + mins}
var _clock = hrs + ":" + mins;
var time;
$('span#clock').append(_clock).show();
