

//getting flash object
function getFlashMovie(movieName)
{
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}



var defaultTab='';
//variable necessary to fix page jump related, because of anchor reference to id

var jFix = 'jFix';

//styling opened tab
function openTab(tab){
   $(tab+jFix).show();
   var li=$('li [href='+tab+']').parent(); 
   li.addClass('on');
            //check if clicked tab is first
      if(li.prev('li').attr('class')=='fTabC'){
         li.prev('li').addClass('fTabC_on');//add class to corner of the first tab
	    }	       
	   else {
		 li.prev('li').addClass('tabC_l')}; 		   
			    //check if clicked tab is last
		 if(li.next('li').attr('class')=='lTabC'){
			 li.next('li').addClass('lTabC_on');
			}
		 else {
		li.next('li').addClass('tabC_on')}; 
}

//get anchor from URL
function getAnchor(){
	var winLink = document.location.toString()
	var tabAnchor='';
	if(winLink.indexOf('#')>0){
	   var hrefString = '#' + winLink.split('#')[1]; //getting anchor from URL
	   $('li.tb a').each(function(){
                   //compare anchor to tab link  		   
	 	  if($(this).attr('href')==hrefString){ 	   
	 	     tabAnchor=hrefString; 	   		   
	 	     }	 		 	   	  
	   }); 
	 }
	return tabAnchor;
}

//main jQuery functions on 
//document ready/load state
$(document).ready(function(){
            //this is necessary to update for JS off functionality
	   $('#tabNavWrapper ul:first').removeClass('tabListNoJS').addClass('tabList');
	   $('#tabNavWrapper').addClass('tabNavWrapper');
	   $('.tabCont').hide(); // Hide all tab content divs  
	  //creating new ids for all tab content divs to fix page jumping 
	  $('#tabs div.tabCont').each(
		 function(){this.id = 	this.id+jFix;					  
		 })

	   var tabToOpen = getAnchor();
	   if(tabToOpen!=''){
	      openTab(tabToOpen);//open tab if anchor exist in URL 
	   }
	   else if(defaultTab!=''){
		   openTab(defaultTab);   //open tab is default tab is defined
		   document.location +=defaultTab;
	   }
	   else {
	   $('#tabs div.tabCont:first').show(); // Show the first div
	   // Show the first div
	   $('ul.tabList li.tb:first').addClass('on'); // Set the class for active state
	   $('ul.tabList li.tb:first').next('li').addClass('tabC_on');
	   $('ul.tabList li:first').addClass('fTabC_on');
	   $('ul.tabList li:first').addClass('fTabC_on');
	   }
	   
	   
	   //click event
	   $('.tabList li a').click(function(){ // When link is clicked
	   $('.tabList li').removeClass('on'); // Remove active class from links
	   $('.tabList li').removeClass('tabC_on');//Remove class from li next to active li 
	   $('.tabList li').removeClass('fTabC_on');//Removes active class from very first li
	   $('.tabList li').removeClass('lTabC_on');//Removes active class from very last li
	   $('.tabList li').removeClass('tabC_l');//Removes active class from left to active li
	   $('#tabs .tabCont').hide(); // Hide all tab content divs
	   var currentTab = $(this).attr('href');	   
	   openTab(currentTab);
	   //document.location.hash = currentTab;
	   window.location.hash = currentTab;
       return false;
  });

	   /** Litrature nav click event **/
	   $('#litTab').click(function(){
	   $('.litContMod').hide(); //hide all litrature content divs
	   $('div.litContMod:first').show(); //show first litrature content div
       $('#litList li').removeClass('on');
	   $('div.litNav li:first').addClass('on');
	   });
	   $('#litList li a').click(function(){
	   $('#litList li').removeClass('on'); // Remove active class from links
	   $(this).parent().removeClass('off').addClass('on'); //Set parent of clicked link class to active 
	   var currentLit = $(this).attr('href'); // Set currentTab to value of href attribute
	    $('div.litContMod').hide(); // Hide all tab content divs
	    $(currentLit).show(); // Show div with id equal to variable currentTab
	     return false;  
	   }); 

        //initilizing tooltips	   
	   tooltip();
});


/***************************************/
/* TOOL TIP FUNCTIONALITY 
/****************************************/

function getElPosX(el)
{
var x = el.offset().left;
var y = el.offset().top;
return y
}

this.tooltip = function(){	
	var pcastSummary;
	/* CONFIG */		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result	
		xOffset = 0;
		yOffset = 0;
		var tTitle;
	
	/* END CONFIG */		
	$("a.ttPodcast").hover(function(e){	
                //remove tooltip
		$("#tooltip").remove();		
                 //update title 
		if(this.title!=''){ tTitle = this.title;}
		else{tTitle = this.rel }
		this.title = "";	
		var tTipDiv = $(this).parent('div');
                //getting x coordinates for tooltip
		var xPos = tTipDiv.offset().left + 8;
                //getting y coordinates for tooltip
		var yPos = tTipDiv.offset().top;
                //offset to display tooltip above hovered link
		var yOffsetUp = tTipDiv.height();
                //creating tooltip
		$('body').append("<p id='tooltip'>"+ tTitle +"</p>");
     	       
               var tHeight=$("#tooltip").height()+7;
		$("#tooltip")
		    .css("top", (yPos - tHeight) + "px") //positioning tooltip
			.css("left",(xPos + xOffset) + "px") //positioning tooltip
			.fadeIn("slow");		
			pcastSummary = tTitle;
    },
	function(){
		if(tTitle=''){ this.title=tTitle;}
		else{this.title = this.rel }		
		$("#tooltip").remove();
    });	
	var pcastFilePath;
        //onlick event for podcast link
	$("a.ttPodcast").click(function(e){									
		        pcastFilePath = this.href;	                	
                $("#utCBoxCont").hide();  //hide list of podcasts            
		        $("#utBoxFlash").show(); //show div with podcast flashplayer
		        $("#utPcastSum").empty().append("<span>"+pcastSummary +"</span>"); //creating podcast summary
		$("#getPodcast").attr("href", pcastFilePath);
		var flashvars = {};
		var params = {};
		params.wmode = "transparent";
		var attributes = {};
		params.allowfullscreen = "true";
		params.allowscriptaccess="always";
		flashvars.podcastLayout= pcastFilePath;
		swfobject.embedSWF("/shared/swf/JuniperMediaModule.swf", "utBoxPlayer", "190", "25", "9.0.0", false, flashvars, params, attributes);
		swfobject.createCSS("#utBoxPlayer","outline:none"); 				
				return false;
	}
	);		
	$("#utBoxBtmNav").click(function(e){
            //trying to stop mp3 player on exit;
           if(isIE6){           
           getFlashMovie("utBoxPlayer").sendTextToFlash('Stop MP3!');
            }
	    $("#utPcastSum").empty();
		$("#utBoxFlash").hide();
		$("#utCBoxCont").show();
	});		
	

};




