$(document).ready(function(){
	
	//if iOS
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if(agentID){ $('title').html('Festroia'); }
	
	
	//get #master height
	window.docHeight = $('#master').height();
	
	
	//add .last class to last child
	$('#main-menu li:last, header .social-media li:last, #pg-noticias .news-ticker article:last, #pg-flashback2011 .flashback2011-cols article:last, #main #pg-video ul li:last, #main #pg-video ul.first li:last, #main #pg-video ul.second li:last').addClass('last');
	
	
	//add jScrollPane to containers
	$('.jscrollpane').jScrollPane({ verticalDragMinHeight:35, verticalDragMaxHeight:35, horizontalDragMinWidth:35, horizontalDragMaxWidth:35, autoReinitialise:true });
	
	
	$('#main-menu li a[href="#"]').click(function(e){ e.preventDefault(); });
	$('#main-menu li.off a').removeAttr('href');
	
	$('#main-menu li').mouseenter(function(){if($(this).has('nav')){ $(this).find('nav').stop(true,true).delay(50).fadeIn(200); }});
	$('#main-menu li').mouseleave(function(){if($(this).has('nav')){ $(this).find('nav').stop(true,true).delay(500).fadeOut(100); }});
	
	
	$(".fancy").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: true,
		'transitionIn'			: 'elastic',
		'transitionOut'			: 'elastic',
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500,
		'overlayColor'			: '#000',
		'overlayOpacity'		: 0.7
	});
	
	
	$(".flashback27-video").fancybox({
		'width'			: 720,
		'height'		: 395,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'opacity'       : true,
		'speedIn'       : 500,
		'speedOut'      : 400,
		'overlayColor'  : "#000",
		'overlayOpacity': 0.3,
		'padding'		: 10,
		'type'			: 'iframe',
		'scrolling'		: 'no'
	});
	
	
	if(!$('#pg-interview').length == 0 || !$('#pg-search').length == 0){
		$('header .lang a').each(function(){
			var h = $(this).attr('href').replace('?','&');
			var loc = window.location.href;
			loc = loc.replace('&l=pt','').replace('&l=en','');
			$(this).attr('href',loc+h);
		});
	}
	
	
	$('header form').submit(function(){
		if($(this).find('.query').val().replace(/\s/g,"") == ''){ return false; }
	});
	
	
});


$(document).load(stickyFooter);
$(document).ready(stickyFooter);
$(document).scroll(stickyFooter);
$(window).resize(stickyFooter);


function stickyFooter(){
	if($(window).height() > window.docHeight)
		$('footer').addClass('sticky');
	else
		$('footer').removeClass('sticky');
}
