<!--  initialize the slideshow when the DOM is ready -->

jQuery(document).ready(function() {


    jQuery('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	$(".ofertaAuto").fancybox({
				'width'				: '60%',
				'height'			: '80%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
		$("#modelo_107").simpletip({ fixed: true,position: 'right',position: ["-170", "-20"], content: $("#modelo_107_contenido").html() });
		$("#modelo_206").simpletip({ fixed: true,position: 'right',position: ["-170", "-20"], content: $("#modelo_206_contenido").html() });

});

            // DOM Ready
                $(function(){
                
                    var HomePage = {
	DEFAULT_MIN_HEIGHT: 725,
	MAST_HEIGHT: 600,
	SLIDE_ID: 1,
	SLIDE_SHOW_ACTIVE: true,
	VIDEO_ACTIVE: false,
	clickTrack: function (cta) {
		var s_track = {};
		s_track.pageName = "CHEVROLET | DIVISIONAL | HOMEPAGE | INDEX";
		s_track.prop1 = "DIVISIONAL";
		s_track.prop2 = "HOMEPAGE";
		s_track.prop3 = "DIVISIONAL | HOMEPAGE";
		s_track.prop4 = "INDEX";
		s_track.prop5 = "HOMEPAGE | INDEX";
		s_track.prop6 = "DIVISIONAL | HOMEPAGE | INDEX";
		s_track.prop7 = HomePage.SLIDE_ID;
		s_track.prop8 = "INDEX | " + HomePage.SLIDE_ID;
		s_track.prop9 = "HOMEPAGE | INDEX | " + HomePage.SLIDE_ID;
		s_track.prop10 = "DIVISIONAL | HOMEPAGE | INDEX | " + HomePage.SLIDE_ID;
		
		if (typeof(cta)!="undefined") {
			s_track.prop20 = "CHEVROLET | DIVISIONAL | HOMEPAGE | INDEX | " + HomePage.SLIDE_ID + " | " + cta.toUpperCase();
		}
		else if (typeof(cta)=="NEXT") {
			s_track.prop20 = "CHEVROLET | DIVISIONAL | HOMEPAGE | INDEX | " + HomePage.SLIDE_ID + " | " + cta.toUpperCase();
		}
		else if (typeof(cta)=="undefined") { // initial load
			s_track.eVar21 = s_track.prop10;
		}
		
		s_track.prop24 = "EN";
		s_track.prop25 = "CHEVROLET";
		s_track.prop26 = ""+ (new Date()).getHours()  +"";
		s_track.prop27 = ""+ weekday[(new Date()).getDay()] +"";
	
		clickTrack(s_track);
		
	},
	setSize: function() {
		var w = $(window).width() * 1; // set to 100% of window width
		var h = $(window).height() * 1; // set to 100% of window height
		
		var as = jQuery('#slider').data('AnythingSlider');
		if(as){
  		leftEdge = 0;
  		$('div.anythingWindow, #slider li.panel').closest('div.anythingSlider').andSelf().width(w);
  		for (var i=0; i < as.pages + 2; i++) {
  			as.panelSize[i] = [w, as.panelSize[i][1], leftEdge];
  			leftEdge += w;
  		}
  		as.gotoPage(as.currentPage);
  		jQuery('#slider').data('AnythingSlider').startStop(HomePage.SLIDE_SHOW_ACTIVE);
  	}
		
		HomePage.setFlashSize();
	},
	setFlashSize: function() {
		var w = $(window).width() * 1; // set to 100% of window width
		var h = $(window).height() * 1; // set to 100% of window height
		
		// scale flash
		if ($("#fl_videoplayer").length) {
			
			if (w < 980) w = 980;
			
			var windowAspectRatio = w / h;
			var videoAspectRatio = 1920 / 1080;
			
			var videoHeight = w / videoAspectRatio;
			
			$("#fl_videoplayer").attr("width",w);
			$("#fl_videoplayer").attr("height",videoHeight);
			$("#page-wrapper").css("min-height", (videoHeight-HomePage.MAST_HEIGHT)+HomePage.DEFAULT_MIN_HEIGHT);
			
		}
	},
	closeVideoPlayer: function() {
		
		HomePage.VIDEO_ACTIVE = false;
		
		// flush player
		$_("#videoplayer_player").html("");
		
		// hide divs
		$_("#videoplayer_container").hide();
		$_("#videoplayer_vignette").hide();
		$_("#videoplayer_player").hide();
		$_("#videoplayer_close").hide();
		
		// turn on slideshow
		$_("div.anythingSlider").css("visibility","visible");
		// move back footer
		$_("#page-wrapper").css("min-height", HomePage.DEFAULT_MIN_HEIGHT);
		
		HomePage.clickTrack("COMMERCIAL CLOSE");
	},
	handleKeyPress: function(evt) {
		var nbr = (window.event)?event.keyCode:evt.which;
	
		if(nbr == 27) {
			if(HomePage.VIDEO_ACTIVE == true) {
				HomePage.closeVideoPlayer();
			}
		}
		
	  	return true;
	}
} 


                
                    $('#slider').anythingSlider({height : null, // Override the default CSS height
                        resizeContents : true, // If true, solitary images/objects in the panel will expand to fit the viewport
                        theme : 'cs-portfolio', // Theme name
                        width :1400,
                        height :600,
                        // Navigation
                        startPanel : 1, // This sets the initial panel
                        hashTags : false, // Should links change the hashtag in the URL?
                        enableKeyboard : true, // if false, keyboard arrow keys will not work for the current panel.
                        buildArrows : true, // If true, builds the forwards and backwards buttons
                        toggleArrows : false, // If true, side navigation arrows will slide out on hovering & hide @ other times
                        buildNavigation : true, // If true, builds a list of anchor links to link to each panel
                        enableNavigation : true, // if false, navigation links will still be visible, but not clickable.
                        toggleControls : false, // if true, slide in controls (navigation + play/stop button) on hover and slide change, hide @ other times
                        appendControlsTo : 'anythingControls', // A HTML element (jQuery Object, selector or HTMLNode) to which the controls will be appended if not null
                        navigationFormatter : null, // Details at the top of the file on this use (advanced use)
                        forwardText : "&raquo;", // Link text used to move the slider forward (hidden by CSS, replaced with arrow image)
                        backText : "&laquo;", // Link text used to move the slider back (hidden by CSS, replace with arrow image)
                        // Slideshow options
                        enablePlay : true, // if false, the play/stop button will still be visible, but not clickable.
                        autoPlay : false, // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
                        autoPlayLocked : false, // If true, user changing slides will not stop the slideshow
                        startStopped : false, // If autoPlay is on, this can force it to start stopped
                        pauseOnHover : false, // If true & the slideshow is active, the slideshow will pause on hover
                        resumeOnVideoEnd : true, // If true & the slideshow is active & a youtube video is playing, it will pause the autoplay until the video is complete
                        stopAtEnd : false, // If true & the slideshow is active, the slideshow will stop on the last page
                        playRtl : false, // If true, the slideshow will move right-to-left
                        startText : "Start", // Start button text
                        stopText : "Stop", // Stop button text
                        delay : 10000, // How long between slideshow transitions in AutoPlay mode (in milliseconds)
                        resumeDelay : 15000, // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds).
                        animationTime : 900, // How long the slideshow transition takes (in milliseconds)
                        // Callbacks
                        onBeforeInitialize : null, // Callback before the plugin initializes
                        onInitialized : null, // Callback when the plugin finished initializing
                        onShowStart : null, // Callback on slideshow start
                        onShowStop : null, // Callback after slideshow stops
                        onShowPause : null, // Callback when slideshow pauses
                        onShowUnpause : null, // Callback when slideshow unpauses - may not trigger properly if user clicks on any controls
                        onSlideInit : null, // Callback when slide initiates, before control animation
                        onSlideBegin : null, // Callback before slide animates
                        onSlideComplete : null // Callback when slide completes
                    });
                    // initialize scrollable
                    $(".scrollable").scrollable({circular: true});
                    	var timer;
                    HomePage.setSize();
                    	$(window).resize(function(){
                    		clearTimeout(timer);
                    		setTimeout( HomePage.setSize, 100);
                    	
                    	});
                     
                });

