  var currentStyle="";
  var activeMenu;
  var currentVid=null;
  var tmpBtnContainer;
  var tmpCurrentContainer;
  var bottomImage;
  var current_desc;
  var isPhone=false;
  
  var static_header="<img src=\"images/staticHeader.jpg\" alt=\"\"/>";
  var menu_descriptions={
		whatwedo:"See why we are the most trusted source for tax solutions that work.",
		refunds:"See how we get more refund in less time than anyone else.",
		research:"See how our research experts rival any in the industry.",
		audits:"See how we keep audits simple and painless.",
		history:"See why we have grown faster than any other tax consulting group.",
		locations:"See our locations throughout the U.S. set up to serve you.",
		contact:"See how easy it is to contact us."
	};

$(document).ready(function(){

	var videoPath;
	isPhone=phoneBrowsing();
	
	//Intialiaze video area for hover effect
	$("#video-area").hover(
		function(){
			$("div.button-wrapper a").removeClass('btnNormal');
			$("div.button-wrapper a").addClass('btnOver');
		},
		function()
		{
			$("div.button-wrapper a").removeClass('btnOver');
			$("div.button-wrapper a").addClass('btnNormal');
		}
	);
	
	//detect user browser
		//if phone,iphone,ipad,smart phone- replace header and video player
	
	/* Ditching the easter egg per Shon's request.
	$("#lnkCopyright").click(function(){
		injectVideo($(this));
		return false;
	});*/
	$("#video-area").live('click',function(){
		
		injectVideo(activeMenu);
		return false;
	});
	
	$("#menus a").click(function(e){
		//Set Element to active
		e.preventBubble=true;
		
			if(activeMenu!=$(this) && activeMenu!="")
				rebind(activeMenu);
				
			set2active($(this));
			showVideo($(this));
			showBottomImage($(this));
		
	});
	//When you leave the menus area the menu description will be reseted to the selected menu
	$("#menus ul").bind('mouseleave',function(){
		var x=$(activeMenu.parent());
		if(x.attr("rel").replace("#desc-","")!=current_desc){
			showTexts(x);		
		}
		
	});
	//When a menu is hovered, show the menu description
	$("#menus li").hover(
		function(){showTexts($(this));},
		function(){}
	);
	//When a menu is hovered change menu style to hovered
	$("#menus a").mouseenter(
		function(e){	
			if(activeMenu!=$(this)){
				over($(this));	
				}
		}
		
	);
	//Set the menu back to normal state
	$("#menus a").mouseleave(
		function(e){
			if(activeMenu!=$(this))		
				leave($(this))
		 }
	);
	
	//Initalized menus,videos and other varriables
	initMenu();

   });
   
   
   //Inject video to the video area
   function injectVideo(active){
   
		var video2play;
	    var x;
	   if(active.attr('id').toLowerCase()=="lnkcopyright"){
			video2play="copyright";
			x=currentVid;
	   }
	   else
	   {
			x=active.attr('rel');
			video2play=x.split("-")[1];
		}
		
//	videoPath="swf/movies/"+video2play+".flv";
	
	//Store taken values to temporary varriables
	tmpBtnContainer=$(x).html();
	
	tmpCurrentContainer=x;
	//Remove current content
	var videoObject=null;
	//Check if client is using phone browser
//	var isPhone=phoneBrowsing();
	
	if(isPhone=='false'){
	videoPath="swf/movies/"+video2play+".flv";
		//set video object/player to flowplayer
		videoObject = "<div style=\"display:block;width:551px;height:309px;\" id=\"player\" href='#'></div>\
							<script type=\"text/javascript\"> \
									flowplayer(\"player\",\
									{src:\"swf/flowplayer.commercial-3.2.2.swf\",bgcolor:'#ffffff'},\
									{\
										key: '#$66af8a38a1b3ad75940',\
										clip:{\
											url:\""+videoPath+"\",\
											provider:'pseudo'\
										},\
										onFinish:function(){\
											showVideo(activeMenu);\
										},\
										plugins:{controls:null,\
											pseudo: {\
												url: 'swf/flowplayer.pseudostreaming-3.2.2.swf'\
											}\
										}\
									});\
							</script>";
	}else{
		//set video player to quicktime
		videoPath="swf/movies/"+video2play+".mp4";
		
		videoObject ="<object \
						width=\"520\" \
						height=\"309\" \
						codebase=\"http://www.apple.com/qtactivex/qtplugin.cab#version=7,2,1,0\" \
						classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\"\
						id=\"movie_id\"  style=\"behavior:url(#qt_event_source);\">\
					<param value=\""+videoPath+"\" name=\"src\"/>\
					<param name=\"postdomevents\" value=\"true\"/>\
					<param value=\"true\" name=\"controller\"/>\
					<param value=\"true\" name=\"autoplay\"/>\
					<param value=\"white\" name=\"bgcolor\"/>\
					<embed \
						width=\"551\" \
						height=\"309\" \
						bgcolor=\"white\" \
						CONTROLLER=\"FALSE\" \
						id=\"movie_embed\" \
						name=\"movie_id\" \
						autoplay=\"true\" \
						controller=\"true\" \
						postdomevents=\"true\" \
						pluginspage=\"http://www.apple.com/quicktime/download/\" \
						src=\""+videoPath+"\" >\
					</embed></object>";
	}
	$(x).html("");
	//Inject Video script
	
	$(x).html(videoObject);
	//If phone, register quicktime dom events
	if(isPhone=='true')RegisterListeners();
	
   }
   //Register event listener
   function myAddListener(obj, evt, handler, captures)//For quicktime use only
    {
        if ( document.addEventListener )
            obj.addEventListener(evt, handler, captures);
        else
            // IE
            obj.attachEvent('on' + evt, handler);
    }
	//Register each listener
    function RegisterListener(eventName, objID, embedID, listenerFcn)//For quicktime use only
    {
        var obj = document.getElementById(objID);
        if ( !obj )
            obj = document.getElementById(embedID);
        if ( obj )
            myAddListener(obj, eventName, listenerFcn, false);
    }
	function movieEnded()//For quicktime use only
	{
		// $('#video-refunds').html("");
		
		showVideo(activeMenu);
	}
    /* define a single function that registers all listeners to call onload */
    function RegisterListeners()//For quicktime use only
    {
       RegisterListener('qt_ended', 'movie_id', 'movie_embed', movieEnded);
    }

   //Initialize Menu
   function initMenu(){
		var defaultMenu=$('a.whatwedo');
		set2active(defaultMenu);
		$('#menu-area-whatwedo').css('display','block');
		$('#video-whatwedo').css('display','block');
		currentVid="#video-whatwedo";
		$("#whatwedo_image").removeClass("img");
		$("#whatwedo_image").addClass("activeImage");
		showTexts(defaultMenu.parent());
   }
	//Sets selected menu to active
	function set2active(el){
	//Set current active menu to normal
		if(activeMenu!=undefined){
			var i=activeMenu.attr("class");
			activeMenu.removeClass(i);
			activeMenu.addClass(i.split("-")[0]);
			}
	//Set selected to active
		var x=el.attr("class");
		
		el.removeClass(x);
		if(x.indexOf("-")>=0)
			el.addClass(x.split("-")[0]+"-active");
		else
			el.addClass(x+"-active");
		
		el.unbind('mouseenter mouseleave');
		activeMenu=el;
	}
	//Executes during mouseover	
	function over(menu){
	
		currentStyle="";
		currentStyle=menu.attr('class');
		
		menu.removeClass(currentStyle);
		menu.addClass(currentStyle+'-hover');
		//show menu hover texts
		
	}
	//This function will show the menu description
	function showTexts(menu){

		var text2show=menu.attr("rel").replace("#desc-","");
		
		var menu_description="";
		menu_description=
		"<div class=\"menu-description\" style=\"\">\
			<span>"+menu_descriptions[text2show]+"</span>\
		</div>";
		
		$("#quote_container").html("");//Make Sure the container is clear
		$("#quote_container").html(menu_description);
		
		$('div.menu-description').css('opacity', '0').fadeTo("normal", 1,function(){
			 $(this).css('filter', 'none');
		});
		//$("div.menu-description").fadeIn("normal",function(){
			// $(this).css('filter', 'none');
		//});
		
		
		current_desc=text2show;
	}
	//This function will display the image at the bottom page
   function showBottomImage(menu){
		//get the target area
		
		var target=menu.attr('href')+"_image";
		if(!$(target).is(":visible")){
			if($("#bottom-inner div.activeImage").length>0){
				$("#bottom-inner div.activeImage").stop(true,true).animate({opacity:'hide'},100,function(){
					$(target).stop(true,true).animate({opacity:'show'},400	).addClass('activeImage');
				}).removeClass('activeImage');
				
			}else{
				$(target).stop(true,true).animate({opacity:'show'},400).addClass('activeImage');
			}
		}
   }
   //This function will show the video of the selected menu
	function showVideo(menuSelected){
	//Check wether the video container contains video player
	//If none show splashes
	//Else inject splashes 
		var x=$(tmpCurrentContainer);
		
		if(x.html()!=null && (x.html().indexOf("player")>=0 || x.html().indexOf("object")>=0)){
			//remove video then inject splashes
			x.html("");
			x.html(tmpBtnContainer.replace("btnOver","btnNormal"));
		}
		
			//Fade out current video container
			//Fade in selected video
			$(currentVid).fadeOut("fast").delay(100).hide();
			var i=menuSelected.attr("rel");
			$(i).fadeIn('slow');
			currentVid=i;
		
	}
	//Executes during mouseout
	function leave(menu){
		menu.removeClass(currentStyle+'-hover');
		menu.addClass(currentStyle);
		
	}
	//Function that will detect mobile,iphone,ipad and smartphone browsing
   function phoneBrowsing(){
   var x='false';
		$.ajax({
			type:'POST',
			url:'detect.php',
			async:false,
			success:function(data){
			
				if(data =='true'){
					//replace header with static header
					$("#banner-wrapper").html("");
					$("#banner-wrapper").html(static_header);
						x=data;
					//replace flowplayer with quicktime
					//$("#video-whatwedo").html("");
					//$("#video-whatwedo").html(tempVid);
					
				}
			}
		});
	return x;
   }
	//This will bind all the mouse events on the menus
	function rebind(sel){
	//Set menu style  to unselected
		currentStyle=sel.attr('class');
		if(currentStyle.indexOf('hover')>=0){
				sel.removeClass(currentStyle);
				sel.addClass(currentStyle.split('-')[0]);
		}
	//Rebind Mouse Events	
		sel.hover
		(
			function()
			{
				over(sel)
			},
			function()
			{
				leave(sel)
			}		
		);
	};

