// JavaScript Document

// Global Variables
var divType="";
var tabWidth;
var tabHieght;
var animationType="";
var tabCurrentCount=0;
var tabCount=0;
var tabCountNow=0;
var activeTabs;
var tabPanelActiveImage, tabPanelNonActiveImage;
var currenthAccordianPanel="#hAccordianContent-1";
var activePanel;
var hAccordian1NonActiveImage,hAccordian1ActiveImage,hAccordian1HoverImage,hAccordianContentWidth,hAccordianSpeed,hAccordianActiveTab1;
var activeBookmark;
var treeOpened

 $(document).ready(function(){
	$('.shrinkPanel > .description').hide();
	$('.shrinkPanel > .clickable').click(function(){
		var toGo=$(this).attr('rel');
		
	 if ($("#"+toGo).is(":hidden")) {
		$("#"+toGo).slideDown("slow");
		$(this).find('span:first').removeClass('notactiveExpand');
		$(this).find('span:first').addClass('activeExpand');
		
	
	} else {
		$("#"+toGo).slideUp("slow");
		$(this).find('span:first').removeClass('activeExpand');
		$(this).find('span:first').addClass('notactiveExpand');
		
	}
	
	
	
	
	
	});
	
	
	
	
	
	
	 var opts =
  // horizontal Dock with images expanding downwards in the vertical axis...
  { align: 'top'
  // set the maximum minor axis (vertical) image dimension to 48px
  , size: 90
  // add labels..
  , labels: true
  // swap the GIF extension for PNG extension for the larger image...
  , source: function(i){ return this.src.replace(/gif$/,'png'); }
  };

	  jQuery('#bottomBrands').jqDock(opts);
	
	
	 $('.swfPreview').click(function(){
			 	var mainFlash = $(this).attr('rel');
				
				$('#'+mainFlash).show('fast');
			 	
			 });
	if($('.treeViewer').size()>0){
		treeOpened = $('#isFirstTopic').attr('rel');
		$('#'+treeOpened).toggle('slow');
		$('#isFirstTopic').removeClass('leftnavTopicNotActive');
		$('#isFirstTopic').addClass('leftnavTopicActive');
		treeOpened= $('#isFirstTopic');
		 $('.leftnavTopic > span').click(function(){
			toClose=$(treeOpened).attr('rel');
			$('#'+toClose).toggle('slow');
			$(treeOpened).removeClass('leftnavTopicActive');
			$(treeOpened).addClass('leftnavTopicNotActive');
			var elementID = $(this).attr('rel');
			 $('#'+elementID).toggle('slow');
			 isClass =$(this).attr('class');
			 if(isClass=="leftnavTopicNotActive"){
				 $(this).removeClass('leftnavTopicNotActive');
				 $(this).addClass('leftnavTopicActive');
			 }else{
				  $(this).removeClass('leftnavTopicActive');
				  $(this).addClass('leftnavTopicNotActive');
			 };
			 treeOpened=$(this);
		 });
	 };
	 
	 
	 
	 
	 
	 if($('.scrollMark').size() >0){
		 $(".scrollMark").click(function(event){
			 //alert('hello');
		//prevent the default action for the click event
		event.preventDefault();
		//alert('hello');
		//get the full url - like mysitecom/index.htm#home
		var full_url = $(this).attr('rel');
		var divTop=$('.scrollAreaContent').offset().top;
		//alert(divTop);
		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		
		//get the top offset of the target anchor
		var target_offset = $("#"+full_url).offset();
		
		var target_top = target_offset.top;
		//alert(target_top);
		var fromTop=target_top-divTop;
		//alert(fromTop);
		//goto that anchor by setting the body scroll top to anchor top
		//$('html, body').animate({scrollTop:target_top}, 500);
		$('.scrollAreaContent').animate({scrollTop: '+=' + fromTop + 'px'}, 1000);
		$("#"+full_url).addClass('activeBookmark');
  		$(activeBookmark).removeClass('activeBookmark');
		$(activeBookmark).addClass('nonactiveBookmark');
		activeBookmark=$("#"+full_url);
	});

		 
	 };
	 
	 
	 
	 
	 if($('.HiddenPanel').size()>0){
		 
		 var pos = $('#mainContent').position();
		 var Width = $('#mainContent').width();
		//$('.HiddenPanel').css('left',((pos.left + Width)-$('.HiddenPanel').width()-25)+"px");

		 $(".HiddenPanelTrigger").click(function(){
			var whichPanel=$(this).attr('rel');
			alert(whichPanel);
			$('#' + whichPanel).toggle("fast");
			//$(this).toggleClass("active");
			return false;
			
		});

	 };
	 
	 
	
	 var dropNow;
	 var dropGo=true;
	 if($('.dropdown').size()>0){
		 $(" .dropdown ul ").css({display: "none"}); // Opera Fix
		$(" .dropdown li").hover(function(){
	if($(this).attr('id')=="nodrop"){
		
	}else{
		if(dropGo!=false){
			dropGo=false;
	$(this).find('ul:first').show('clip', { percent: 100 },'medium' );
	setTimeout(function() {dropGo=true;}, 100 );


		
	dropNow=$(this).find('ul:first');
		}
	//dropNow.slideDown('medium').show();
	};
	},function(){
		//dropNow.css({display: "none"});
		$(this).find('ul:first').stop(false, true).hide(); 
		//$(this).find('ul:first').css({display: "none"});

		});


	 };
	 
	 
	 if($('#verticalScroll > li').size()>0){
		
		$('#verticalScroll > li').click(function(){
			toPosistion=$(this).attr('rel');
			panelHeight=$('.scrollPanelPane').height();
			toGoto=toPosistion*panelHeight*-1;
			$('#scrollArea').stop().animate({top: toGoto+"px"},{duration:500});
			
			
			//alert(panelHeight);
		});
	 };
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	//Check to see if tabPanel exists
	if($('#tabControl').size()>0){
		//alert('hello');
		tabWidth =$('#tabPanelMain').width()/1;
		tabHeight = $('#tabPanel').height()/1;
		tabCount=$('#tabControl > div').size()/1;
		activeTabs = $('#tabControl > #tabButton:first > a').attr('rel');
		
		$(activeTabs).addClass('activeTab');
		//Register and initialize tabControl button click
		var hasOptions = $('#tabPanelMain').attr('rel');
		var optionsArray = hasOptions.split(',');
		if(optionsArray.length > 0){
			var isMouseover = optionsArray[1];
			tabPanelActiveImage = optionsArray[3];
			tabPanelNonActiveImage = optionsArray[2];
			
			var mouseOver = isMouseover.split(':');
			if(mouseOver.length>0){
				var isYesMouseOver = mouseOver[1];
				
				if(isYesMouseOver=='yes'){
					$('#tabButton > a').mouseover(function(event){
						
						var tabTo = $(this).attr('rel');//get the destination tab from clicked link
			
			var toMove =(((tabTo-1)*tabWidth)+"px");//calculate distance to travel
			
			var tabAnimate= $(('#panel-'+tabTo)).attr('rel');//het animate options from destination panel
			
			var optionsArray = tabAnimate.split(',');
			//set animate variables
			var direction = "Left:";
			var speed = '800';
			
			//register specified option
			
			//get Direction 
			if(optionsArray.length>0){
				//direction=optionsArray[0];
				
			//Get speed	
			}
			if(optionsArray.length>1){
				speed=optionsArray[1];
			}
			//animate the #tabPanel division
			$(this).parent().css('background-image',' url('+tabPanelActiveImage+')');
			$('#tabPanel').stop().animate({left:(parseInt(toMove)*-1)}, {duration:speed}); 
			$(activeTabs).css('background-image',' url('+tabPanelNonActiveImage+')');
			
			activeTabs=$(this).parent();
			return false;
						
						
					});
				};
			}
		
		};
		
		$("#tabButton > a").click(function(event){
			var myParent=$(this).parent().attr('id');
			//alert(myParent);
			var tabTo = $(this).attr('rel');//get the destination tab from clicked link
			
			var toMove =(((tabTo-1)*tabWidth)+"px");//calculate distance to travel
			
			var tabAnimate= $(('#panel-'+tabTo)).attr('rel');//het animate options from destination panel
			
			var optionsArray = tabAnimate.split(',');
			//set animate variables
			var direction = "Left:";
			var speed = '800';
			
			//register specified option
			
			//get Direction
			if(optionsArray.length>0){
				//direction=optionsArray[0];
				
			//Get speed	
			}
			if(optionsArray.length>1){
				speed=optionsArray[1];
			}
			$(this).parent().css('background-image',' url('+tabPanelActiveImage+')');
			//animate the #tabPanel division
			$('#tabPanel').stop().animate({left:(parseInt(toMove)*-1)}, {duration:speed}); 
			$(activeTabs).css('background-image',' url('+tabPanelNonActiveImage+')');
			
			activeTabs=$(this).parent();
			//disable the clicked link from redirection
			return false;
		});
	}
	
	
	
	
	//check to see if toggleView is around ie:http://spyrestudios.com/how-to-create-a-sexy-vertical-sliding-panel-using-jquery-and-css3/
   if($('#toggleGrow').size()>0){
	   $("#toggleGrow > a").click(function(event){
		   	var optionsNow = $(this).attr('rel');
			var optionsArray=optionsNow.split(',');
			var speed='fast';
			if(optionsArray.size()>0){
				speed=optionsArray[0];
			}
			$("#togglePanel").toggle(speed);
	        $(this).toggleClass("active");
        return false;
	    });
   }
   
   //Check to see if vertical Accordian Panel is around ie:http://www.sohtanaka.com/web-design/simple-accordion-w-css-and-jquery/
   if($('#vAccordianPanel').size()>0){
	   
	   //Set default open/close settings
		$('.vAccordianContent').hide(); 
		//Hide/close all containers
		
		$('.vAccordianTab:first').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

		//On Click
		$('.vAccordianTab').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container 			is closed...
			$('.vAccordianTab').removeClass('active').next().slideUp(); 						//Remove all .acc_trigger classes and slide up the immediate next container
			$(this).next().slideDown(); //Add 			.acc_trigger class to clicked trigger and slide down the immediate next 	container
		}
		return false; //Prevent the browser jump to the link anchor
		});


   }
   


if($('#hAccordianPanel').size()>0){
	var hAccordianPanelRel = $('#hAccordianPanel').attr('rel');
	var hAccordianOptions =hAccordianPanelRel.split(',');
	if(hAccordianOptions.length > 5){
		hAccordian1NonActiveImage = 								hAccordianOptions[1];
		hAccordian1ActiveImage=hAccordianOptions[0];
		hAccordianContentWidth=hAccordianOptions[3];
		hAccordianSpeed=hAccordianOptions[4];
		hAccordian1HoverImage=hAccordianOptions[2];
		var isMouseOver=hAccordianOptions[5];
		if(isMouseOver=="yes"){
			$('#hAccordianPanel > #hAccordianTab').mouseover(function(event){
			
			
			
		var toPanel = "#hAccordianContent-"+$(this).attr('rel');
		
		if (currenthAccordianPanel==toPanel){
			
		}else{
			//alert('True');
			
			$(currenthAccordianPanel).stop().animate({"width": 0+"px"},hAccordianSpeed);
			//$(currenthAccordianPanel).stop().effect('clip',{},500);
			
			$(toPanel).stop().animate({width: hAccordianContentWidth},hAccordianSpeed); 
			
			$(hAccordianActiveTab1).css('background-image',' url('+hAccordian1NonActiveImage+')');
			hAccordianActiveTab1=$(this);
			
			currenthAccordianPanel= toPanel;
			//alert('finished');
			$(this).css('background-image',' url('+hAccordian1ActiveImage+')');
		}
		
			
			
			});
		};
	}else{
		alert("not enough parameters set in H Accordian Panel");
	};
	$('#hAccordianContent-1').animate({width: hAccordianContentWidth},hAccordianSpeed);
	
	
	
	
		$('#hAccordianPanel > #hAccordianTab').click(function(event){
			
		
	
		var toPanel = "#hAccordianContent-"+$(this).attr('rel');
		
		if (currenthAccordianPanel==toPanel){
			
		}else{
			//alert('True');
			
			$(currenthAccordianPanel).animate(
            {"width": 0+"px"},
            hAccordianSpeed);
			$(toPanel).animate({width: hAccordianContentWidth},hAccordianSpeed); 
			
			$(hAccordianActiveTab1).css('background-image',' url('+hAccordian1NonActiveImage+')');
			hAccordianActiveTab1=$(this);
			
			currenthAccordianPanel= toPanel;
			//alert('finished');
			$(this).css('background-image',' url('+hAccordian1ActiveImage+')');
		}
		
		
		
	});
	//slideMenu.build('hAccordianPanel',750,25,8,1)
};


 });
 
 
 function closePanel(thisId){
	// Reset previous sliders
		for (var i = 0; i < $('.slidePanel').size(); i++) {
			var sliderId = "slidePanel" + i;
			
			//var pulloutId = sliderId + "_pullout";
			
			// Only reset it if it is shown
			
			if ($("#" + sliderId).width() > 35) {

				if (sliderId == thisId) {
					// They have clicked on the open slider, so we'll just close it
						$("#" + sliderId).animate({width: "35px"}, 1000);
					showSlider = false;
				}else{

					// Close the slider
					$("#" + sliderId).animate({width: "35px"}, 1000);
				}
			}else{
				if (sliderId == "slidePanel" + thisId) {
					$("#" + sliderId).animate({width: "300px"}, 1000);
				}
			}
		}
}

function slidePanel(whichPanel){
	
	if(whichPanel==pnlClicked){
		//$('#slidePanel'+whichPanel).animate({width: '-=300'},1000,function(){  });
		
		//$('#slidepnlContent'+whichPanel).fadeOut();
		//pnlClicked="";
	}else{
		
		//$('#slidePanel'+whichPanel).animate({width: '+=300'},1000,function(){ });
		
		//$('#slidepnlContent'+whichPanel).fadeIn();
		pnlClicked=whichPanel;
		
	}
	
}

function checkToClose(toCheck) {
	if(pnlClicked !=toCheck){
		alert(toCheck +' '+pnlClicked);
		$('#slidePanel'+whichPanel).animate({width: '-=300'},1000,function(){ });
	}
}


		
		
function rotateDiv (){
	$('#rotated').rotate3Di('-=90', 500,{sideChange: mycallback});
	
	$('#rotated').rotate3Di('-=90', 500);
}
 
 
