function backgroundPos() {
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
		if (window.innerWidth != currentWidth) {
			currentWidth = window.innerWidth;
			var orient = (currentWidth == 320) ? "profile" : "landscape";
			document.body.setAttribute("orient", orient);
			window.scrollTo(0, 1);
		}
	}
    var myWidth = 0, padding = 0, liWidth = 0, divQtos = 0;
	
    myWidth = $('body').width() - 110;
	liWidth = $('.projetos li').width() + 20;
	
	divQtos = Math.floor(myWidth / liWidth);
	padding = Math.floor(((myWidth % liWidth)/divQtos)/2)+10;
	
    $('.projetos li').css('padding','10px '+padding+'px');
};

var resizeTimer = null;

$(document).ready(function() {
	
	// espalha thumbs
	backgroundPos();
    $(window).bind('resize', function() {
        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(backgroundPos, 100); 
	});
	
	// iphone
	if((!navigator.userAgent.match(/iPhone/i)) && (!navigator.userAgent.match(/iPod/i))) {
		// modal projetos
		$('.projetos a').nyroModal({
			height: 395,
			width: 870
	    });
		
		// nome dos projetos
		$('.projetos > ul > li > p').css('visibility','hidden');

		$('.projetos a').hover(
			function(){
				$(this).parents('li').find('p').css('visibility','visible');
			},
			function(){
				$(this).parents('li').find('p').css('visibility','hidden');
			}
		);

		
	} else {
		$('.projetos a').removeClass('nyroModal');
		$('.projetos a').click(function() {
			window.open($(this).attr('href'));
			return false;
		});
	}
	
	// empresa modal menor
	$('.nav-empresa a').click(function(e) {
	    e.preventDefault();
	    $.nyroModalSettings({
			height: 350,
			width: 400
	    });
	    return false;
	});
	// o q fazemos modal maior
	$('.nav-fazemos a').click(function(e) {
	    e.preventDefault();
	    $.nyroModalSettings({
			height: 500,
			width: 400
	    });
	    return false;
	});

});

function rota(){
	navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
}
function foundLocation(position){
	var lat = position.coords.latitude;
	var long = position.coords.longitude;
	alert('Found location: ' + lat + ', ' + long);
	location.href='http://maps.google.com/maps?saddr='+lat+','+long+'&daddr=R.+Vergueiro,+1421+-+Vila+Mariana,+S%C3%A3o+Paulo+-+SP,+04101-000,+Brazil';
}
function noLocation(){
	location.href='http://maps.google.com/maps?q=R.+Vergueiro,+1421+-+Vila+Mariana,+S%C3%A3o+Paulo+-+SP,+04101-000,+Brazil&ie=UTF8&hl=en&cd=1&sll=37.0625,-95.677068&sspn=23.875,57.630033&hq=&hnear=R.+Vergueiro,+1421+-+Vila+Mariana,+S%C3%A3o+Paulo+-+SP,+04101-000,+Brazil&t=h&ll=-23.574372,-46.640375&spn=0.012095,0.02517&z=16&iwloc=A'
}

function detectFlash() {
    return DetectFlashVer(10, 0, 0);
}

function goToHtml() {
    $.cookie("mayaSiteVersionPreference", "html", { expires: 365 });
    location.replace("/");
}

function goToFlash() {
    $.cookie("mayaSiteVersionPreference", "flash", { expires: 365 });
    location.replace("/");
}
