

/* slideshow campanha  */

var id = 0;
var total = 2;
var foto = 0;
var imageWidth = 1280;
var imageHeight = 777;
var registerPoint = {x:0, y:0};
var containerPos = 0;
var clock;
var slideDelay = 7;

/*  */


var browserWidth = 0;
var browserHeight = 0;
var minBrowserWidth = 980;
var minBrowserHeight = 870;
var maxBrowserHeight = 870;
var IE = false;
var version = 0



if($.browser.msie){
	IE = true;
	version = Math.round($.browser.version);
}

var slideShowObj = {
	
	// init
	
	init : function(){
		this.controls();
		//slideShowObj.moveContainer();
		//slideShowObj.startCounter();
	},
	
	// add event listeners
	
	controls : function(){

		// campanha slide show arrow buttons
		
		$('#leftarrow, #rightarrow').bind('click', function(event){
			clearTimeout(clock);
			event.preventDefault();
			var bt = $(this).attr('id');
			slideShowObj.moveSlideShow(bt);
		});
	},
	
	// prepare to move campanha slide show based on witch button was pressed
	
	moveSlideShow : function(bt){ 
		var idAnterior = id;
		if(bt) bt == 'rightarrow' ? (id < total-1 ? id ++ : id = 0) : (id > 0 ? id -- : id = total-1);
		slideShowObj.moveContainer(idAnterior);
	},
	
	// move campanha slide show container
	
	moveContainer : function(idAnterior){
		containerPos = -(id * imageWidth);
		$('#campanhaimages').stop().animate({'left':containerPos}, (idAnterior == undefined ? 2000 : 1000), 'easeinout');
		$('#campanhaupperimages').stop().animate({'left': containerPos*1.5}, (idAnterior == undefined ? 2000 : 1000), 'easeinout');
	},

	
	nextSlide : function(){
		slideShowObj.moveSlideShow('rightarrow');
	},
	
	updateMeasures : function(){
		
		/* slide show Campanha */
		var regX = ((browserWidth-imageWidth)/2);
		registerPoint.x = regX;
		$('#campanhaslideshowwrapper').css({'left':registerPoint.x});
		
	}
};

/* Resize  */

function onResizeHandler(){
  if( typeof( window.innerWidth ) == 'number' ){
	
    //Non-IE

    browserWidth = window.innerWidth;
    browserHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	
    //IE 6+ in 'standards compliant mode'

    browserWidth = document.documentElement.clientWidth;
    browserHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	
    //IE 4 compatible

    browserWidth = document.body.clientWidth;
    browserHeight = document.body.clientHeight;
  }

  // update measures 
  
  browserWidth = browserWidth < minBrowserWidth ? minBrowserWidth : browserWidth;
  browserHeight = browserHeight < minBrowserHeight ? minBrowserHeight : browserHeight > maxBrowserHeight ? maxBrowserHeight : browserHeight;
  
  slideShowObj.updateMeasures();
};


var home = {
	props : {
		LIs:null,
		loadedImages:0
	},
	initImages : function(){
		home.props.LIs = $('#campanhaimages li');
		for(var i = 0; i < home.props.LIs.length; i++){
			$('<img/>', {
			    'id':'image'+i,
			    'title':'Moda Infantil - Coleção Verão 2012 - Green by Missako - '+i,
				'alt':'Moda Infantil - Coleção Verão 2012 - Green by Missako - '+i
			}).appendTo(home.props.LIs[i]);
		};
		home.loadImages();
	},
	loadImages : function(){
		for(var i = 0; i < home.props.LIs.length; i++){
			var imgSrc = 'images/home/slideshow/campanha/green_by_missako_inverno_2011_'+(i+1)+'.jpg';
			var img = $('#image'+i);
			img.css({'opacity':0});
			img.one('load', function(){
				var img = $(this);
				img.parent().removeClass('spinner');
				img.animate({'opacity':1}, {duration:200});
				home.props.loadedImages++;
				if(home.props.loadedImages == 2){
					slideShowObj.init();
				}
			});
			img.attr({'src':imgSrc});
			img.each(function() {
	          //Cache fix for browsers that don't trigger .load()
	          if(this.complete) $(this).trigger('load');
	        });
			
		}
	},
	printFloater : function(){
		var flashvars = {};
		var params = {};
			params.wmode = "transparent";
		var attributes = {};
			attributes.id = "floater";
		swfobject.embedSWF("swf/floater.swf", "floater", "1000", "610", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
	}
};

(function($){
	window.onresize = onResizeHandler;
	onResizeHandler();
	$(document).ready(function(){
		home.initImages();
		//home.printFloater();
	});
	
})(window.jQuery)

function removeFloater(){
	jQuery(".floater").css("display", "none");
}

