

//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')}; 
$('html').scrollTop(0);
}

//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();
	
	/** company flyout navigation **/
	$('.foCompanyNav').click(function(){
					$('.foCompanyNav').removeClass("h3Selected")
					$(this).addClass("h3Selected");
					$('.foCompanyCol').hide();	
					var index = this.id.substring(13,14);
					var foCompanyName = '#foCompanyNav'+index;
					$(foCompanyName).show();
			});
	
	/** solution flyout navigation **/
	$('.foSolutionNav').click(function(){
					$('.foSolutionNav').removeClass("h3Selected")
					$(this).addClass("h3Selected");
					$('.foSolutionCol').hide();	
					var index = this.id.substring(14,15);
					var foCompanyName = '#foSolutionNav'+index;
					$(foCompanyName).show();
			});
	
});

/************************* 
* Carousel begin
* We use the initCallback callback
* to assign functionality to the controls
*************************/
		function mycarousel_initCallback(carousel) {
			jQuery('.jcarousel-control a').bind('click', function() {
			    var clicked = $(this);
			    clicked.addClass('selected');
			    clicked.siblings().removeClass('selected');
		            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		            return false;
		    	});
		
		    	jQuery('#mycarousel-next').bind('click', function() {
		            carousel.next();
		            return false;
		    	});
		
		    	jQuery('#mycarousel-prev').bind('click', function() {
		            carousel.prev();
		            return false;
		    	});
		};
		
		/*
		 * it will append class="selected" into <a>
		 * <a href="#">1</a> to <a href="#" class="selected">1</a>
		 */
		function highlight(carousel, obejctli,liindex,listate){
		     jQuery('.jcarousel-control a:nth-child('+ liindex +')').attr("class","selected");
		};
			
		/*
		 * it will remove last selected slide from <a>
		 * <a href="#" class="selected">1</a> to <a href="#">1</a>
		 */
		 function removehighlight(carousel, obejctli,liindex,listate){
		 	jQuery('.jcarousel-control a:nth-child('+ liindex+')').removeAttr("class","selected");
		 };
		 
		/* our event listener receives the carousel
		 * object, so we just check to see if it's 
		 * turned itself off or not...
		 */
		 function afterAnimation(carousel){
		         if(carousel.autoStopped){
		             carousel.startAuto()
		         }
    		 }
		 
		
		// Ride the carousel...
		jQuery(document).ready(function() {
			if ($('#mycarousel').length) {
		    jQuery("#mycarousel").jcarousel({
		        scroll: 1,
		        initCallback: mycarousel_initCallback,
		        wrap: 'both',
		        // This tells jCarousel NOT to autobuild prev/next buttons
		        buttonNextHTML: null,
		        buttonPrevHTML: null,
		        itemVisibleInCallback:  highlight,
			itemVisibleOutCallback: removehighlight,
			itemLastInCallback:{
				onAfterAnimation: afterAnimation
                	}
		    });
		    }
		});
		
/********************* 
* Carousel end
********************/

/***************************************/
/* 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();
	});		
	

};


/***************************************/
/* Country selection functionality 
/****************************************/

jQuery(document).ready(function() {
	if($.browser.msie && $.browser.version=="6.0") {
		$('#CountrySelectorBG').activeXOverlap();
}
	
	$('#countryChange').click(function() {
		$('#CountrySelectorBG').show();
		
		//if($.browser.msie && $.browser.version=="8.0") {
		//$('#CountrySelector').addClass('CountrySelectorIE8');
		//}
	})
						
	$('#countryMap').click(function() {
		$('#CountrySelectorBG').show();
		
	//			if($.browser.msie && $.browser.version=="8.0") {
	//	$('#CountrySelector').addClass('CountrySelectorIE8');
	//	}
		
	})
						
			
	if ($('#CountrySelector #countryselect').length) { 
		$('.label_check input').ezMark();
						
		var path = document.location.pathname;
						
		//get locale
		path = path.substr(0,7);
		path = replaceAll(path,"/","-");
						
		$('#userSelectedCntry').val(path);
		path='#'+path;
		if ($(path).length) {
			$(path).addClass('selected');
		} else {
			//default to us
			$('#-us-en-').addClass('selected');
			$('#userSelectedCntry').val('-us-en-');
		}
							
		$('.countryLink').click(function() {
			if (this.parentNode.id) {
				var newValue = this.parentNode.id;
				var prevValue = $('#userSelectedCntry').val();
											
				if (prevValue) {
					prevValue = '#'+prevValue;
					$(prevValue).removeClass();
				}
							
				$('#userSelectedCntry').val(newValue);
				newValue = '#'+newValue;
				$(newValue).addClass('selected');
				var userSelectedCountry = $('#userSelectedCntry').val();
				var cookie = replaceAll(userSelectedCountry,"-","/");
											
				//if choose this choice is checked, need to set the cookies.
				if ($('#countryselect').is(':checked')) {
					setCookie('countryCookie', cookie,'\/',365);
				}
							
			}
		})
									
		$('#countryselect').change(function() {
			if ($('#countryselect').is(':checked')) {
				var userSelectedCountry = $('#userSelectedCntry').val();
				var cookie = replaceAll(userSelectedCountry,"-","/");
				setCookie('countryCookie', cookie,'\/',365);
			}
		})
						
		$('#closeButton').click(function() {
			$('#CountrySelectorBG').hide();
		})
	}
						
});

	jQuery.fn.activeXOverlap = function() { 
		$(this).each(function(i){
	       		var h   = $(this).outerHeight();
	        	var w   = $(this).outerWidth();
	        	var iframe  = '<!--[if IE 6]>' +
	        	'<iframe src="javascript:false;" style="height: ' +
	                h +
	                'px; width: ' +
	                w +
	                'px;" class="selectOverlap">' +
	                '</iframe>'+
	                '<![endif]-->'
	           
	        	$(this).prepend(iframe);
    		});
    	}
    	
 /***************************************/
 /* Feedback widget 
 /***************************************/
 
 $(document).ready(function() {
 				if ( $('#actFeedback').length ) {
					$('#actFeedback').highlightFade({color:'yellow',speed:2000,iterator:'sinusoidal'});
					}
					
				 if ( $('#frmfeedback').length ) {
					$("#fbComments").textlimit('span.remainingChars',800);	
					}	
					
					$('.stars a').mouseover(function(){

						var title = $(this).attr('title');

						$('.stars a').each(function(){
							$(this).attr('class','starfull');
							return ($(this).attr('title') != title);
						});

  					});

  					$('.stars a').mouseleave(function(){
						$('.stars a').each(function(){
							$(this).attr('class','starempty');
						});
  					});

  					$('#closeFeedback').click(function(){
						$('#frmfeedback')[0].reset(); // clear the form on close
						$("#fbComments").textlimit('span.remainingChars',800);			
	  					$('.innerRating').hide();
						$('#feedRating').animate({height:0, width: 200},300);
	  					$('#feedRating').hide();
  					});

  					$('.stars a').click(function(){
						var position = $('#actFeedback').position();
						$('#feedRating').css('left', position.left-5);
						$('#feedRating').css('top', position.top-10);

						$('#feedRating').animate({height:240, width: 385},300);
						$('#feedRating').show();
						$('.innerRating').show();
						$('#loadImage').hide();

						$('.starspop span').each(function(){
							$(this).attr('class','starempty');
						});

						var title = $(this).attr('title');

						$('.starspop span').each(function(){
							$(this).attr('class','starfull');
							return ($(this).attr('title') != title);
						});

						$('input[name="rating"]').attr('value',title);
					});

  					$('.starspop span').click(function(){

						var title = $(this).attr('title');

						$('.starspop span').each(function(){
							$(this).attr('class','starempty');
						});

						$('.starspop span').each(function(){
							$(this).attr('class','starfull');
							return ($(this).attr('title') != title);
						});

						$('input[name="rating"]').attr('value',title);
					});


               $('.feedbackBtn').click(function() {		
						var id = $(this).attr('id');
                        var index = id.indexOf("_submitBtn");
                        if (index > 0) {
                                    var formName = id.substr(0,index);
                                    var str = $('#'+formName).serialize();

									$('.innerRating').hide();
									$('#loadImage').show();

									$.ajax({
											url: "/webform/submitForm.do",
											type: "POST",
											data: str,
											dataType: "html",
											success: function(){
												$('#feedRating').animate({height:0, width: 200},300);
												$('#loadImage').hide();
												$('#feedRating').hide();
												$('#ratBtn').hide();
												$('#result').show().highlightFade({color:'yellow',speed:2000,iterator:'sinusoidal'});
												$('#frmfeedback')[0].reset(); // clear the form on close
											},
					 					    error: function(){
												$('#feedRating').hide();
											    alert('Server error. Please try again later.');
												}
									});
                		  }
				});
		});
