
// AU Flipbook

var createFlash = function(panel,file,container,wd,ht,vars) {
            var c = $("#"+container);
            var p = $("#"+panel+" .flashcontainer");
            
            if (swfobject.hasFlashPlayerVersion("8")) {   

                   if (c.length == 0) {
                        var newContainer = $("<div id="+container+"></div>");
                        p.append(newContainer);
	           }

                   if(container) {
                        var att = { data:file, width:wd, height:ht };
                        var par = { menu:"false", wmode:"transparent", "flashvars":vars };
                        var id = container;
                        setTimeout(function() {
                                    swfobject.createSWF(att, par, id);
                        }, 600);
                   }
            } else {
               
                   if ($("#"+panel+" .flashcontainer .dl-prompt").length == 0) {
                        var dlPrompt = $("<p class='dl-prompt'>Please install the latest version of the <a href='http://get.adobe.com/flashplayer/'>Adobe Flash Player</a>.</p>");
                        p.append(dlPrompt);
	           }     
            }
};

var removeFlash = function(container) {
            swfobject.removeSWF(container);       
}

var initTab = function(tab) {

      switch(tab) {
        case 1:     
            removeFlash("swf-tour");
            removeFlash("swf-dimensions");
            //Google Analytics Event Tracking
            if (typeof _gaq != "undefined" && typeof _gaq.push != "undefined") {
                         _gaq.push(['_trackPageview', '/home/tab/1']);
            };
            break;
        case 2:
            removeFlash("swf-dimensions");
            createFlash("panel-2", "http://static.eharmony.com.au/assets/au/flipbook/ehTour-AU-960x550.swf", "swf-tour", "576", "329");
            //Google Analytics Event Tracking
            if (typeof _gaq != "undefined" && typeof _gaq.push != "undefined") {
                        _gaq.push(['_trackPageview', '/home/tab/2']);
            };
            break;
        case 3:
            removeFlash("swf-tour");
            createFlash("panel-3", "http://static.eharmony.com.au/assets/au/flipbook/Dimensions-AU-960x550.swf", "swf-dimensions", "576", "329");
            //Google Analytics Event Tracking 
            if (typeof _gaq != "undefined" && typeof _gaq.push != "undefined") {
                        _gaq.push(['_trackPageview', '/home/tab/3']);
            };
            break;
        case 4:
            removeFlash("swf-tour");
            removeFlash("swf-dimensions");
            createFlash("panel-4", "http://static.eharmony.com.au/assets/au/flipbook/FlipBook-videoPlayer.swf", "swf-members", "600", "430", "videoPath=http://static.eharmony.com.au/assets/au/flipbook/video-au/");
            if (typeof _gaq != "undefined" && typeof _gaq.push != "undefined") {
                        _gaq.push(['_trackPageview', '/home/tab/4']);
            };
            break;
      };
           
                  
            
}

$('.nav1').click(function() {  
            $('#slideshow-overview').cycle(0);
            initTab(1);
            return false;  
}); 
 
$('.nav2').click(function() {  
            $('#slideshow-overview').cycle(1);
            initTab(2);
            return false;  
}); 

$('.nav3').click(function() {  
             $('#slideshow-overview').cycle(2);
            initTab(3);
            return false;  
});
            
$('.nav4').click(function() {  
            $('#slideshow-overview').cycle(3);
            initTab(4);
            return false;  
});


// Parse Querystring to get Tab
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


$(document).ready(function() {
            
            // Set Starting Slide Based On URL Hash
            var anchorindex = 0
                
            var hash = $.getUrlVar('tab');
     
            if (hash) {
                   anchorindex = hash-1;
                   hashindex = parseInt(hash);
                   initTab(hashindex);
            }
            
            //Intiate slideshow
            if ($('#slideshow-overview').length) {
                        
                        $('#slideshow-overview').cycle({
                           fx: 'wipe',
                           cssBefore: {clip: 'rect(0px 701px 90px 600px)'},
                           timeout: 0,
                           autostop: 0,
                           speed: 500,
                           startingSlide: anchorindex
                       });
             };
             
             
             setTimeout(function() {
                $(".curl img").animate({
			width:600,
                        height:600,
                        marginRight: "-15px"
		}, 250);
                $(".curl img").animate({
			width:450,
                        height:450,
                        marginRight: "-12px"
		}, 250);  
                $(".curl img").animate({
			width:600,
                        height:600,
                        marginRight: "-15px"
		}, 350, function() {
                        // Animation complete
                        $(".next").zIndex(100);
                        $(".curl img").zIndex(10);
                });  
            }, 1500);
            

}); //end onReady
