
/// Declare the global options used by Fancy Box 
var fancyBoxOptions = 
    { // Options for the new Fancy box
        'type'          : 'ajax'
       ,'transitionIn'	: 'none'
       ,'transitionOut'	: 'none'
       ,'autoDimensions': false
       ,'titleShow'     : false
       ,'width'         : 620
       ,'height'        : 800
       ,'onComplete'    : function(){bindLinksClick('.heajax');}
       ,'onCleanup'     : function(){hePageStat.logPage('back_to_index.php'); heEffects.hideValidaitons('#contactform'); }
    };


/// Load the passed link into the AJAX Fancy Box
function loadFancyBox(linkPath, linkTitle) {
           // The link path contain the full path to the page
           // We need to strip it and get only the path to the 
           // AJAX page. 
           // The ? is the delimiter between the main page and the AJAX page
           var hash = (linkPath.split('?', 2))[1];
           // If found a Content AJAX Page 
           if(hash) {
           
                // Modify the link to indicate to the content page 
                // that the index page is already open 
                var ajaxLink = hash + '?i=1';
                var theLinkObj = $("a[href*='" + hash +"']").last().clone();
                
                if (typeof linkTitle !== 'undefined') {
                   linkTitle = (linkTitle.length>0)?linkTitle:((theLinkObj.length == 0)?'Harvest Earnings Inc.':$(theLinkObj).attr('title'));
                   if (linkTitle.length>0) {
                      document.title = linkTitle;
                   }
                   // Log page hit statistics
                   hePageStat.logPage((linkTitle.length>0)?linkTitle:hash);
                } else {
                   // Log page hit statistics
                   hePageStat.logPage(hash);
                }

                // If Fancy Box AJAX DIV already open, load new content
                if($('#fancybox-wrap').is(":visible")){
                   // remove validation messages if exists
                   heEffects.hideValidaitons('#contactform');
                   $('#fancybox-inner').load(ajaxLink,function(){bindLinksClick('.heajax');});
                } 
                else 
                {
                   // Load the new conted to a new Fancy Box
                   // First find the link (a element) with the hash value in its href
                   if ($("a[href*='" + hash +"']").length == 1){
                         var boxOptions = {};
                         
                         $.extend(boxOptions, fancyBoxOptions, {'href':  ajaxLink });
                         $(theLinkObj).attr('href', ajaxLink);
                         $(theLinkObj).attr('title', linkTitle);
                         $.fancybox((theLinkObj.get(0)) //The link to open
                                   ,boxOptions 
                                   );
                   }
                }

           }
}


// set onlick event for links (A) to be intrcepted by 
// the history plugin and sent to the loadFancyBox function
// The history plugin, assumes that each link in the set 
// contains a relative path to an AJAX page 
function bindLinksClick(selector){
         $(selector).each(function(index) {
                            $(this).unbind('click.fb');
                            $(this).bind('click.fb'
                                        , function(e) {
                                             var linkPath = this.href;
                                             var part1 = window.location.href;
                                             // check if the link is an anchor within the document 
                                             // or an actual AJAX call.
                                             if (linkPath.indexOf('.')> -1){ 
                                                // The link has a file extention
                                                // Now clean part 1
                                                if (part1.indexOf('?')> -1){
                                                   part1 = part1.substr(0,part1.indexOf('?'));
                                                } 
                                                if (part1.indexOf('#')> -1){
                                                   part1 = part1.substr(0,window.location.href.indexOf('#'));
                                                } 
                                                linkPath = part1 + "?" + this.href.substr(this.href.lastIndexOf('/')+1);
                                                var linkTitle = ((this.title.length>0)? this.title : this.href);
                                                // First, Check if the page was last in the history stack, if yes, then Reload
                                                var HState = History.getState();
                                                if(HState != null && HState.url == linkPath){
                                                   loadFancyBox(linkPath, linkTitle);
                                                } else {
                                                   // Add this link to the history 
                                                   // Which causes a statechange event to fire
                                                   // and in turn load the page into the Fancy box
                                                   History.pushState(null, linkTitle, linkPath);
                                                }
                                                return false;
                                             } else {
                                               // this is an internal document link, we need to scroll to the location
                                                return true;
                                             }
                                          }
                                        )
                            }
                          );
}

$(window).load(function(){ 
                  $("#preloader").css("display","none");
                  $("#content_inside").css("display","block");
                  //let's get this party started
                  StartParty();
                  $("#ceoquotes").show();
                  //$("#ceoquotes").textTicker('#quotestarget',6000);
                  $('#ceoquotes').cycle({
		        fx     : "scrollUp"
                       ,timeout: 6000
                       ,random : true
                       ,pause  : 1
                       ,next   : "#ceoquotes"
                      }
                   );

                 }
              );

$(window).unload(function() {
                //var goingTo = window.location.href;
                //alert ('goingTo = ' + goingTo);
                // Log page as exit statistics
                hePageStat.logPage('exit.php');
});

$(document).ready(function(){ 
	
                //hiding things that need hidin'
                $(".box1hover").hide();
                $(".box2hover").hide();
                $(".box3hover").hide();
                $(".box4hover").hide();
                $(".box5hover").hide();
                $(".box6hover").hide();
                $(".box7hover").hide();
                $(".box8hover").hide();
                $(".box9hover").hide();
                $(".box10hover").hide();
                $(".box11hover").hide();
                $("#lines1").hide();
                $("#lines2").hide();
                $("#lines3").hide();
                $("#lines4").hide();
                $("#lines5").hide();
                $("#box4").hide();
                $("#box5").hide();
                $("#box6").hide();
                $("#box7").hide();
                $("#box8").hide();
                $("#box9").hide();
                $("#box10").hide();
	
	        // Prepare the fancyboxery links 
                $(".iframe").fancybox(fancyBoxOptions);
	
		$(".hashover").hover(
		 function()
		 {
		  this.src = this.src.replace("_up","_down");
		 },
		 function()
		 {
		  this.src = this.src.replace("_down","_up");
		 }
		);
                
                // Bind to History State Change to populate the FancyBox with new link
                History.Adapter.bind(
                         window
                        ,'statechange'
                        ,function(){ // Note: We are using statechange instead of popstate
                           // Log the State
                           var State = History.getState(); // Note: We are using History.getState() instead of event.state
                           loadFancyBox(State.url, State.title);
                         }
                );
	       
                // Bind Click even for links to cause a History changestate
                bindLinksClick('.heajax');                
		
		//box1's hover
		$(".hover1").hover(
		 function()
		 {			 
			 $(".box1hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box1hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box2's hover
		$(".hover2").hover(
		 function()
		 {			 
			 $(".box2hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box2hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box3's hover
		$(".hover3").hover(
		 function()
		 {			 
			 $(".box3hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box3hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box4's hover
		$(".hover4").hover(
		 function()
		 {			 
			 $(".box4hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box4hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box5's hover
		$(".hover5").hover(
		 function()
		 {			 
			 $(".box5hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box5hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box6's hover
		$(".hover6").hover(
		 function()
		 {			 
			 $(".box6hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box6hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box7's hover
		$(".hover7").hover(
		 function()
		 {			 
			 $(".box7hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box7hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box8's hover
		$(".hover8").hover(
		 function()
		 {			 
			 $(".box8hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box8hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box9's hover
		$(".hover9").hover(
		 function()
		 {			 
			 $(".box9hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box9hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
		
		//box10's hover
		$(".hover10").hover(
		 function()
		 {			 
			 $(".box10hover").animate({
					opacity: 1
					}, 100	);
		 },
		 function()
		 {
			 $(".box10hover").animate({
					opacity: 0
					}, 100	);
		 }
		);
                // Record the visit to the main Index page				
                hePageStat.logPage('index.php');

});

function StartParty() {
   $(".do1").animate(
             {left: '+=0'}
           , 1000
           , function(){calldo1();}
           );
}

function calldo1() {

				$(".do1").animate({
				left: '+=420',
				width: 0
				}, 300,
				
				function(){
				calldo2();}
				
				);

}

function calldo2() {

				$(".do2").animate({
				top: 130,
				height: 0
				}, 200,
				
				function(){
				calldo3();}
				
				);
				
				$(".do1").hide();

}

function calldo3() {

				$(".do3").animate({
				width: 0
				}, 300,
				
				function(){
				calldo4();}
				
				);
				
				$(".do2").hide();

}

function calldo4() {

				$(".do4").animate({
				height: 0
				}, 200,
				
				function(){
				calldo5();}
				
				);
				
				$(".do3").hide();

}

function calldo5() {

				$(".do4").hide();

				$(".do5").animate({
				width: 0,
				left: '+=300'
				}, 400,
				
				function(){
				calldo6();}
				
				);

}

function calldo6() {

				$("#lines1").show(
				'blind',
				{direction: "vertical"},
				300,
				
				function(){
				calldo7();}
				
				);
				
				$("#box5").hide();
				
	//enable box1's link
	$(".box1hover").animate({
	opacity: 0
	}, 0	);
	$(".box1hover").show();

}

function calldo7() {

				$(".whitebox1b").animate({
				width: 0,
				left: '+=310'
				}, 300,
				
				function(){
				calldo8();}
				
				);

}

function calldo8() {

				$(".whitebox2b").animate({
				height: 0,
				top: '+=45'
				}, 200,
				
				function(){
				calldo9();}
				
				);
				
				$(".whitebox1b").hide();

}

function calldo9() {

				$(".whitebox3b").animate({
				width: 0
				}, 300,
				
				function(){
				calldo10();}
				
				);
				
				$(".whitebox1c").animate({
				width: 0,
				left: '+=345'
				}, 300
				
				);
				
				$(".whitebox2b").hide();

}

function calldo10() {

				$(".whitebox4b").animate({
				height: 0
				}, 200,
				
				function(){
				calldo11();}
				
				); 

				$(".whitebox2c").animate({
				height: 0,
				top: '+=86'
				}, 200
				
				);
				
				$(".whitebox3b").hide();
				
				$(".whitebox2b").hide();

}

function calldo11() {

				$(".whitebox5b").animate({
				width: 0,
				left: '+=264'
				}, 400,
				
				function(){
				calldo12();}
				
				); 

				$(".whitebox3c").animate({
				width: 0
				}, 400
				
				);
				
				$(".whitebox4b").hide();
				
				$(".whitebox2c").hide();
	
}

function calldo12() {

			$(".whitebox4c").animate({
			height: 0
			}, 300,
			
			function(){
			calldo13();}
			
			); 
			
			$(".whitebox5b").hide();
			
			$(".whitebox3c").hide();
	
                        //enable box2's link
			$(".box2hover").animate({
			opacity: 0
			}, 0	);
			$(".box2hover").show();
		
		
		}
		
function calldo13() {

				$(".whitebox5c").animate({
				width: 0,
				left: '+=264'
				}, 300,
				
				function(){
				calldo14();}
				
				);
				
				$(".whitebox4c").hide();

}

function calldo14() {

	$("#lines2").show(
	'blind',
	{direction: "vertical"},
	300,
	
	function(){
	calldo15();}
	
	);
	
	$(".whitebox5c").hide();
		
	//enable box3's link
	$(".box3hover").animate({
	opacity: 0
	}, 0	);
	$(".box3hover").show();

}

function calldo15() {

				$("#box4").show(
				'blind',
				{direction: "horizontal"},
				300,
				
				function(){
				calldo16();}
				
				); 

				$("#lines3").show(
				'blind',
				{direction: "vertical"},
				300
				);	

}

function calldo16() {

	$("#box5").show(
	'blind',
	{direction: "horizontal"},
	300,
	
	function(){
	calldo17();}
	
	); 

	//enable box4's link
	$(".box4hover").animate({
	opacity: 0
	}, 0	);
	$(".box4hover").show();

}

function calldo17() {

	$("#box6").show(
	'blind',
	{direction: "horizontal"},
	300,
	
	function(){
	calldo18();}
	
	); 
	
	//enable box5's link
	$(".box5hover").animate({
	opacity: 0
	}, 0	);
	$(".box5hover").show();

}

function calldo18() {

	$("#lines4").show(
	'blind',
	{direction: "vertical"},
	300,
	
	function(){
	calldo19();}
	
	); 

  //enable box6's link
	$(".box6hover").animate({
	opacity: 0
	}, 0	);
	$(".box6hover").show();

}

function calldo19() {

				$("#box7").show(
				'blind',
				{direction: "horizontal"},
				200,
				
				function(){
				calldo20();}
				
				);
}

function calldo20() {

	$("#box8").show(
	'blind',
	{direction: "horizontal"},
	200,
	
	function(){
	calldo21();}
	
	);
	
	//enable box7's link
	$(".box7hover").animate({
	opacity: 0
	}, 0	);
	$(".box7hover").show();
}

function calldo21() {

	$("#box9").show(
	'blind',
	{direction: "horizontal"},
	200,
	
	function(){
	calldo22();}
	
	);
	
	$("#lines5").show(
	'blind',
	{direction: "vertical"},
	300
	); 
	
	//enable box8's link
	$(".box8hover").animate({
	opacity: 0
	}, 0	);
	$(".box8hover").show();
				
}

function calldo22() {

	$("#box10").show(
	'blind',
	{direction: "horizontal"},
	200,
	
	function(){
	calldo23();}
	
	);
	
	//enable box9's link
	$(".box9hover").animate({
	opacity: 0
	}, 0	);
	$(".box9hover").show();
}

function calldo23() {
   //enable box10's link
   $(".box10hover").animate({opacity: 0}, 0);
   $(".box10hover").show();
}


