function ajust() {
	$('#section').width($('#crop').width() - $('#sidebar').outerWidth());

	if(isiApple() == true) {
		$('.arrows').remove();
		$('#crop, body').width($('#main').width() + $('#sidebar').outerWidth(true));
	}

//	$('.arrows.right').stop(true).fadeTo(250, .7);
//	$('.arrows.left').stop(true).fadeTo(250, 0);
} ajust();



function video(filme) {

	$.getScript('http://ajax.googleapis.com/ajax/libs/swfobject/2/swfobject.js', function(data, textStatus) {

		$('#section').after('<div id="mask"></div> <div id="video"><div id="stage"></div></div><img id="fechar" src="http://www.arezzo.com.br/verao2012/assets/images/zoom-hide-white.png" />');

			$('#fechar').css({cursor: 'pointer', position: 'fixed', top: 20, right: 20, zIndex: 99999}).live('click', function () {
				$('#video').fadeOut(500, function () {
				
					$('#mask, #video, #fechar').remove();
				})
			});

			$('#mask').css({height: '100%', width: '100%', background: '#000', position: 'fixed', top: 0, left: 0, zIndex: 99999}).fadeTo(0, 0).fadeTo(500, .7, function () {
			$('#video').css({height: 360, width: 540, background: '#000', position: 'fixed', top: '50%', left: '50%', marginTop: -180, marginLeft: -270, zIndex: 999999});

			if(isiApple() == true) {

				$('#video').html('<video width="100%" poster="http://www.arezzo.com.br/verao2012/temp/' + filme + '.jpg" height="100%" controls=""><source src="http://www.arezzo.com.br/verao2012/uploads/' + filme + '.mp4"></video>');
			} else {
				swfobject.embedSWF('assets/swf/player.swf', 'stage', '100%', '100%', '10.0.0',false,false,{allowScriptAccess: 'always', wmode: 'transparent', allowFullscreen: 'true', flashvars: 'video=http://www.arezzo.com.br/verao2012/uploads/' + filme + '.flv&foto=http://www.arezzo.com.br/verao2012/temp/' + filme + '.jpg&autoPlay=true'});
			}
		});

	});

}


//HOME
$('#home').each(function() {

	var testing,
		side,
		dif;

	$(window).bind('load resize', ajust);

	$('.arrows.left').bind('mouseenter mousedown', function(i) {
		if (!testing) {
			testing = setInterval(function() {
				side = 150;
	   
				if($('#main').position().left + side <= 0) {
	
					$('.arrows.right').stop(true).fadeTo(250, .8);
	
					$('#main').stop(true).animate({
						left: $('#main').position().left + side
					}, 1500);
	
				}else{
					$('.arrows.left').stop(true).fadeTo(250, 0);
					$('#main').stop(true).animate({ left: 0 }, 1500);
				}
	
			}, 100);
		}
	}).bind('mouseleave mouseup', function(e) {
		clearInterval(testing);
		testing = null;
	});


	$('.arrows.right').fadeTo(250, .8).bind('mouseenter mousedown', function(i) {
		if (!testing) {
			dif = $('#section').width() - $('#main').width();
			testing = setInterval(function() {
	
				side = -150;
	
				if( $('#main').position().left > dif) {
	
					$('.arrows.left').stop(true).fadeTo(250, .8);
	
					$('#main').stop(true).animate({
						left: $('#main').position().left + side
					}, 1500);
	
				} else {
					$('.arrows.right').stop(true).fadeTo(250, 0);
					$('#main').stop(true).animate({ left: dif  }, 1500);
				}
	
			}, 100);
		}
	}).bind('mouseleave mouseup', function(e) {
		clearInterval(testing);
		testing = null;
	})


	//Init Nivo
	$('.nivo').nivoSlider({
		effect: 'boxRandom'
		, slices: 6
		, boxCols: 6
		, boxRows: 4
		, pauseTime: 7500
		, animSpeed: 750
		, pauseOnHover: false
		, afterLoad: function () {
			$('.nivo').css({backgound: 'none'});
		}
	});


	//Init slides
	$(function() {
		$('.slides').slides({
			  container: 'container'
			, effect: 'slide'
			, generateNextPrev: true
			, hoverPause: true
			, pagination: false
			, pause: 5000
			, play: 10000
			, preload: true
			, preloadImage: 'assets/images/load.gif'
		});
	});
});

