/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

/*
to get flash to display an image in thickbox call:
javascript:tb_show("","http://jquery.com/demo/thickbox/images/plant1.jpg","gallery-plants")

parameters are (textCaption,url to the first image to show,mmGalleryArray)

mmGalleryArrays look like this: 
mmGalleryArray = new Array();
mmGalleryArray[0] = new Image();
mmGalleryArray[0].href="foo.jpg";
mmGalleryArray[1] = new Image();
mmGalleryArray[1].href="bar.jpg";

generate it in the page using xsl, match the order of the images in the xml
 */

// to create product table comparison wrapper - use this parameter -
// compPP=true to add print and other buttons


var tb_pathToImage = "../../../../../../shared/img/global/anim-loading.gif";
var tb_pathToClose_btn = "../../../../../../shared/img/global/btn-close.gif";
var tb_iconPrint_btn = "../../../../../../shared/img/global/btn-print.gif";
var TB_bottom = "<div class=\"TB_bottom\"><div class=\"TB_bottom_left\"></div><div class=\"TB_bottom_right\"></div></div>";
var TB_compPP_more = "<div id=\"TB_compPP_more\"><div id=\"leftPPScroll\">\&nbsp;</div> <div id=\"ppNavCont\">More Products</div> <div id=\"rightPPScroll\">\&nbsp;</div></div>";
var showRoller='false';
var compTblLeft;

//I need this for product comparison table to create link for print button
var fullURL ;
//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
            



});


//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);         
	this.blur();
	return false;
	});
}

function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

        
	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		} else {//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
			
	   }else{ 
	   		baseURL = url;
	   }
	   

	   var tb_query_string = url.replace(/^[^\?]+\??/,'')
	   var locationStringParams = tb_parseQuery(tb_query_string);
	   var tb_xslP = locationStringParams['xslPath'];
	   var tb_fP="http://www.juniper.net/fragment.do";
	   var tb_xmlP = locationStringParams['xmlPath'];
	   var fullPCompURL = "http://"+location.hostname + tb_fP + "@xmlPath="+tb_xmlP + "&xslPath="+tb_xslP;
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);
       var TB_pagesize = tb_getPageSize();
       var TB_maxWidth = TB_pagesize[0] - 150;
	   var TB_maxHeight = TB_pagesize[1] - 150;   

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
				
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_imgOrImgs = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[rel="+imageGroup+"]").get();
				if(TB_TempArray.length>1){TB_imgOrImgs = "images"}
				else{TB_imgOrImgs = "image"}
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						//if (!(TB_TempArray[TB_Counter].href == url)) {		
						if (TB_TempArray[TB_Counter].href.indexOf(url) == -1) {		
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								//changed span to div
								TB_NextHTML = "<div id='TB_next'><a href='#' title='Next'>&nbsp;</a></div>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								//changed span to div
								TB_PrevHTML = "<div id='TB_prev'><a href='#' title='Previous'>&nbsp;</a></div>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = (TB_Counter + 1) +" of "+ (TB_TempArray.length)+" "+TB_imgOrImgs;											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
                     
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 60;
			TB_HEIGHT = imageHeight + 80;
			
			//EDITED - according to styleguide
			//$("#TB_window").append("<div class='TB_top'><div id='TB_caption'><h2>"+caption+"</h2><div id='TB_secondLine'>" + TB_imageCount + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src=\""+tb_pathToClose_btn+"\"/></a></div></div><div class=\"TB_image_cont\"><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></div>"+TB_PrevHTML + TB_NextHTML +TB_bottom); 		
			$("#TB_window").append("<table id='tb_dropShadow' cellpadding='0' cellspacing='0' border='0'><tr><td id='tb_tl'><img src='../../../../../../shared/img/global/bkg-tb-tl.png' class='png'/></td><td id='tb_tm'>&#160;</td><td id='tb_tr'><img src='../../../../../../shared/img/global/bkg-tb-tr.png' class='png'/></td></tr><tr><td id='tb_ml'>&#160;</td><td id='tb_mm'><div class='TB_top'><div id='TB_caption'><h2>"+caption+"</h2><div id='TB_secondLine'>" + TB_imageCount + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src=\""+tb_pathToClose_btn+"\"/></a></div></div><div class=\"TB_image_cont\"><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></div></td><td id='tb_mr'>&#160;</td></tr><tr><td id='tb_bl'><img src='../../../../../../shared/img/global/bkg-tb-bl.png' class='png'/></td><td id='tb_bm'>&#160;</td><td id='tb_br'><img src='../../../../../../shared/img/global/bkg-tb-br.png' class='png'/></td></tr></table>"+TB_PrevHTML + TB_NextHTML); 		

			$("#TB_closeWindowButton").click(tb_remove);
			

			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
				//HERE
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load").remove();
			$("#TB_ImageOff").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			try {
				dgi('TB_next').style.top = dgi('TB_Image').offsetTop +(dgi('TB_Image').offsetHeight/2) + 10 + 'px';
			} catch(e) {}
			try {
				dgi('TB_prev').style.top = dgi('TB_Image').offsetTop +(dgi('TB_Image').offsetHeight/2) + 10 + 'px';
			} catch(e) {}
			};
			
			imgPreloader.src = url;
		}else{//code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 60 || 650; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 60 || 460; //defaults to 440 if no paramaters were added to URL
			
			//alert('tb='+TB_HEIGHT+' max='+ TB_maxHeight);
                       if(TB_HEIGHT>TB_maxHeight){
                        
                         TB_HEIGHT=TB_maxHeight;
                        }
                        
                        
                        
            ajaxContentW = TB_WIDTH - 40;
			//ajaxContentH = TB_HEIGHT - 45;
            ajaxContentH = TB_HEIGHT - 50;
			
                        //compare those with actual screen size to 
                        //make sure this will resize on lower resolution screen
            		iframeContentW = 680;
			iframeContentH = 440;
			iframeW = 680;
			//adding checking for height/width
			var uSplit = url.split('&');
			for (i in uSplit) {
				curSplit = uSplit[i];	
				if (curSplit.indexOf("height=") != -1) {
					iframeContentH = curSplit.split("=")[1];
					ajaxContentH = curSplit.split("=")[1];
				}
				if (curSplit.indexOf("width=") != -1) {
					iframeContentW = curSplit.split("=")[1];
					iframeW = curSplit.split("=")[1];
					ajaxContentW = curSplit.split("=")[1];
				}
			}
			TB_WIDTH = iframeW; //to TB_position 360

			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						//$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'><h2>"+caption+"</h2></div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src="+tb_pathToClose_btn+" alt=\"Close\"/></a> </div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+iframeContentW+"px;height:"+iframeContentH+"px; overflow:hidden;' > </iframe>"+TB_bottom);
						$("#TB_window").append("<table id='tb_dropShadow' cellpadding='0' cellspacing='0' border='0'><tr><td id='tb_tl'><img src='../../../../../../shared/img/global/bkg-tb-tl.png' class='png'/></td><td id='tb_tm'>&#160;</td><td id='tb_tr'><img src='../../../../../../shared/img/global/bkg-tb-tr.png' class='png'/></td></tr><tr><td id='tb_ml'>&#160;</td><td id='tb_mm'><div id='TB_title'><div id='TB_ajaxWindowTitle'><h2>"+caption+"</h2></div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src="+tb_pathToClose_btn+" alt=\"Close\"/></a> </div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+iframeContentW+"px;height:"+iframeContentH+"px; overflow:hidden;' scrolling='no'> </iframe></td><td id='tb_mr'>&#160;</td></tr><tr><td id='tb_bl'><img src='../../../../../../shared/img/global/bkg-tb-bl.png' class='png'/></td><td id='tb_bm'>&#160;</td><td id='tb_br'><img src='../../../../../../shared/img/global/bkg-tb-br.png' class='png'/></td></tr></table>");
						$("#TB_window").css({width:iframeW+60+"px"});
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
							
						//$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'><h2>"+caption+"</h2></div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src="+tb_pathToClose_btn+" alt=\"Close\"/></a> </div></div><div id='TB_ajaxContent' style='width:auto;height:"+ajaxContentH+"px'></div>"+TB_bottom);
						$("#TB_window").append("<table id='tb_dropShadow' cellpadding='0' cellspacing='0' border='0'><tr><td id='tb_tl'><img src='../../../../../../shared/img/global/bkg-tb-tl.png' class='png'/></td><td id='tb_tm'>&#160;</td><td id='tb_tr'><img src='../../../../../../shared/img/global/bkg-tb-tr.png' class='png'/></td></tr><tr><td id='tb_ml'>&#160;</td><td id='tb_mm'><div id='TB_title'><div id='TB_ajaxWindowTitle'><h2>"+caption+"</h2></div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src="+tb_pathToClose_btn+" alt=\"Close\"/></a> </div></div><div id='TB_ajaxContent' style='height:"+ajaxContentH+"px'></div></td><td id='tb_mr'>&#160;</td></tr><tr><td id='tb_bl'><img src='../../../../../../shared/img/global/bkg-tb-bl.png' class='png'/></td><td id='tb_bm'>&#160;</td><td id='tb_br'><img src='../../../../../../shared/img/global/bkg-tb-br.png' class='png'/></td></tr></table>");
//changed 	ajaxContentW to auto for adjax window width					
						}
//Product comparison table						
						if(params['compPP']=="true"){
							TB_WIDTH = parseInt(iframeContentW) + 60;

							$("#TB_overlay").unbind();				
							var tb_CP_options = "<div class=\"TB_compPP_options\"><div id=\"TB_compPP_print\"><a href=\""+fullPCompURL+"\" target=\"_newPrintWin\" title='Print'><img src=\""+tb_iconPrint_btn+"\" alt=\"Print Product Comparison\"/></a></div>"+TB_compPP_more+"</div>";
							$("#TB_title").append("<div class=\"clear\" id=\"prodCompNa\">"+tb_CP_options +"</div>");
							$("#TB_ajaxContent").css({float:'left'});
							$("#TB_title").css("margin-right", "25px");
							$("#TB_window").css({width:TB_WIDTH +'px'});
							$("#TB_window").css({height:iframeContentH +'px'});
                                                        showRoller='true';
							
						}
						
						else{//ajax modal
							//I have to add this to fix double creation of ajaxcontent div
							if(params['modal']=="true"){
							$("#TB_overlay").unbind();
							$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
							}
						}
					}
					else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			$("#TB_closeWindowButton").click(tb_remove);
     

	            $("#rightPPScroll").mouseover(function() {
												  
												  //var compTblLeft = $("#TB_compTbl").css("left");
												  compTblWidth = $("#TB_compTbl").width();
												  compTblLeft = compTblWidth - 520;
                                                                                                  if(compTblLeft>0){

												  compTblLeft = "-"+compTblLeft+"px";
												  $("#TB_compTbl").animate({left: compTblLeft}, {duration: 3000, easing: "swing"});
                                                                                                   }
												  }).mouseout(function(){$("#TB_compTbl").stop();
                                                                                                  

                                                                                               });
            $("#leftPPScroll").mouseover(function() {$("#TB_compTbl").animate({left: "0px"}, {duration: 3000, easing: "swing"})}).mouseout(function(){$("#TB_compTbl").stop()});
	

			

			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
                                                  //var TB_compTbl_module_w =  $("#TB_ajaxContent").width() +'px'; 
                                                 
                                                 //$("#TB_compTbl_module").css({width:TB_WIDTH+'px'});  
                                                 //if(isIE6){
                                                 //$("#TB_compTbl_module").css({height:TB_HEIGHT-25 +'px'});
                                                  //}
                                                 //else{ 
                                                 //    $("#TB_compTbl_module").css({height:TB_HEIGHT-25 +'px'}); 
                                                  // }
    
						$("#TB_window").css({display:"block"});
                                                 if(showRoller=='true'){
                                                 if(isIE6){
                                                  $("#tb_tr").html("<img class=\"png\" src=\"../../../../../../shared/img/global/bkg-tb-tr.png\"/>");
                                                  $("#tb_tl").html("<img class=\"png\" src=\"../../../../../../shared/img/global/bkg-tb-tl.png\"/>");
                                                  $("#tb_br").html("<img class=\"png\" src=\"../../../../../../shared/img/global/bkg-tb-br.png\"/>");
                                                  $("#tb_bl").html("<img class=\"png\" src=\"../../../../../../shared/img/global/bkg-tb-bl.png\"/>");
                                                  }  
//alert("Setting module2 "+ iframeContentW +'px');
							$("#TB_compTbl_module").css({width:iframeContentW +'px'});
							$("#TB_compTbl_module").css({height:iframeContentH +'px'});
                                                if ($('#TB_compTbl').width()<$("#TB_compTbl_module").width()){
                                                     $('#TB_compPP_more').hide();
                                                       }
                                                   }
						}); 
                                         
					            
                         }
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
     
         
		
	} catch(e) {
		//nothing here
	}

    

  

                                             
                                                                                      

}

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
	$('#tb_flash').remove();
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}



function tb_position() {
//original 	
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
//edited
//	$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/ );
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   //alert(Params['compPP']);
   return Params;
   
}



function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
   
	arrayPageSize = [w,h];
	return arrayPageSize;
}




function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}

function setup_Scroller(compTblOffset){        
           if(compTblOffset<0){$("#TB_compPP_more").hide();}       
}


/*FLASH EMBED*/

function tb_flash(src, xmlfile, width, height, url, title, queryparam){

if (url && title) {
// alert(url + title);
// dcsMultiTrack('DCS.dcsuri',url,'WT.ti',title, queryparam);
dcsMultiTrack('DCS.dcsuri',url,'WT.ti',title,'DCS.dcsqry',queryparam);
}
// dcsMultiTrack('DCS.dcsuri','http://www.juniper.net/us/en/local/demos/junos-062609-test/','WT.ti','JUNOS Demo TEST');
	
	if(!width || !height){
		width = '822';
		height = '531';	
	}
	
	$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
	$("#TB_overlay").click(tb_remove);
	
	if(tb_detectMacXFF()){
		$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}
	
	$('body').append('<div id="tb_flash"><div id="flash_swf" style="height:'+height+';width:'+width+';"></div></div>');
	
	
	$('#flash_swf').flash({	   
		src: src,
	    width: width,
	    height: height,
		wmode: 'transparent',
		flashvars: {
			xmlfile: xmlfile
		}
	});
	
	
}

(function(){
	
var $$;

$$ = jQuery.fn.flash = function(htmlOptions, pluginOptions, replace, update) {
	
	// Set the default block.
	var block = replace || $$.replace;
	
	// Merge the default and passed plugin options.
	pluginOptions = $$.copy($$.pluginOptions, pluginOptions);


	// Detect Flash.
	if(!$$.hasFlash(9)) {
		// Use Express Install (if specified and Flash plugin 6,0,65 or higher is installed).
		if(pluginOptions.expressInstall && $$.hasFlash(6,0,65)) {
			// Add the necessary flashvars (merged later).
			var expressInstallOptions = {
				flashvars: {  	
					MMredirectURL: location,
					MMplayerType: 'PlugIn',
					MMdoctitle: jQuery('title').text() 
				}					
			};
		// Ask the user to update (if specified).
		} else if (pluginOptions.update) {
			// Change the block to insert the update message instead of the flash movie.
			block = update || $$.update;
		// Fail
		} else {
			// The required version of flash isn't installed.
			// Express Install is turned off, or flash 6,0,65 isn't installed.
			// Update is turned off.
			// Return without doing anything.
			return this;
		}
	}
	
	// Merge the default, express install and passed html options.
	htmlOptions = $$.copy($$.htmlOptions, expressInstallOptions, htmlOptions);
	
	// Invoke $block (with a copy of the merged html options) for each element.
	return this.each(function(){
		block.call(this, $$.copy(htmlOptions));
	});
	
};
/**
 *
 * @name flash.copy
 * @desc Copy an arbitrary number of objects into a new object.
 * @type Object
 * 
 * @example $$.copy({ foo: 1 }, { bar: 2 });
 * @result { foo: 1, bar: 2 };
 *
**/
$$.copy = function() {
	var options = {}, flashvars = {};
	for(var i = 0; i < arguments.length; i++) {
		var arg = arguments[i];
		if(arg == undefined) continue;
		jQuery.extend(options, arg);
		// don't clobber one flash vars object with another
		// merge them instead
		if(arg.flashvars == undefined) continue;
		jQuery.extend(flashvars, arg.flashvars);
	}
	options.flashvars = flashvars;
	return options;
};
/*
 * @name flash.hasFlash
 * @desc Check if a specific version of the Flash plugin is installed
 * @type Boolean
 *
**/
$$.hasFlash = function() {
	// look for a flag in the query string to bypass flash detection
	if(/hasFlash\=true/.test(location)) return true;
	if(/hasFlash\=false/.test(location)) return false;
	var pv = $$.hasFlash.playerVersion().match(/\d+/g);
	var rv = String([arguments[0], arguments[1], arguments[2]]).match(/\d+/g) || String($$.pluginOptions.version).match(/\d+/g);
		
	var my_ver = parseInt(pv[0]);
	var min_ver = parseInt(rv[0]);
	
	if(my_ver >= min_ver){
		return true;
	}else{
		return false;
	}

	// major version, minor version and revision match exactly
};
/**
 *
 * @name flash.hasFlash.playerVersion
 * @desc Get the version of the installed Flash plugin.
 * @type String
 *
**/
$$.hasFlash.playerVersion = function() {
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { axo.AllowScriptAccess = 'always';	} 
			catch(e) { return '6,0,0'; }				
		} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
	// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}		
	}
	return '0,0,0';
};
/**
 *
 * @name flash.htmlOptions
 * @desc The default set of options for the object or embed tag.
 *
**/
$$.htmlOptions = {
	height: 240,
	flashvars: {},
	pluginspage: 'http://www.adobe.com/go/getflashplayer',
	src: '#',
	type: 'application/x-shockwave-flash',
	width: 320		
};
/**
 *
 * @name flash.pluginOptions
 * @desc The default set of options for checking/updating the flash Plugin.
 *
**/
$$.pluginOptions = {
	expressInstall: false,
	update: true,
	version: '9.0.0'
};
/**
 *
 * @name flash.replace
 * @desc The default method for replacing an element with a Flash movie.
 *
**/
$$.replace = function(htmlOptions) {
	this.innerHTML = '<div class="alt">'+this.innerHTML+'</div>';
	jQuery(this)
		.addClass('flash-replaced')
		.prepend($$.transform(htmlOptions));
};
/**
 *
 * @name flash.update
 * @desc The default method for replacing an element with an update message.
 *
**/
$$.update = function(htmlOptions) {
	var url = String(location).split('?');
	url.splice(1,0,'@hasFlash=true&');
	url = url.join('');
	var msg = '<div style="background:#fff;padding:20px;ext-align:center;">This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="'+url+'">Click here.</a></div>';
	this.innerHTML = '<span class="alt">'+this.innerHTML+'</span>';
	jQuery(this)
		.addClass('flash-update')
		.prepend(msg);
};
/**
 *
 * @desc Convert a hash of html options to a string of attributes, using Function.apply(). 
 * @example toAttributeString.apply(htmlOptions)
 * @result foo="bar" foo="bar"
 *
**/
function toAttributeString() {
	var s = '';
	for(var key in this)
		if(typeof this[key] != 'function')
			s += key+'="'+this[key]+'" ';
	return s;		
};
/**
 *
 * @desc Convert a hash of flashvars to a url-encoded string, using Function.apply(). 
 * @example toFlashvarsString.apply(flashvarsObject)
 * @result foo=bar&foo=bar
 *
**/
function toFlashvarsString() {
	var s = '';
	for(var key in this)
		if(typeof this[key] != 'function')
			s += key+'='+encodeURIComponent(this[key])+'&';
	return s.replace(/&$/, '');		
};
/**
 *
 * @name flash.transform
 * @desc Transform a set of html options into an embed tag.
 * @type String 
 *
 * @example $$.transform(htmlOptions)
 * @result <embed src="foo.swf" ... />
 *
 * Note: The embed tag is NOT standards-compliant, but it 
 * works in all current browsers. flash.transform can be
 * overwritten with a custom function to generate more 
 * standards-compliant markup.
 *
**/
$$.transform = function(htmlOptions) {
	htmlOptions.toString = toAttributeString;
	if(htmlOptions.flashvars) htmlOptions.flashvars.toString = toFlashvarsString;
	return '<embed ' + String(htmlOptions) + '/>';		
};

/**
 *
 * Flash Player 9 Fix (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
 *
**/
if (window.attachEvent) {
	window.attachEvent("onbeforeunload", function(){
		__flash_unloadHandler = function() {};
		__flash_savedUnloadHandler = function() {};
	});
}
	
})();

