function IDHTV_special(pi_href){
		var caption = this.title || this.name || "";
		var group = this.rel || false;
		IDHTV_show(caption, pi_href, group);
}
function vthdi_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	vthdi_show(t,a,g);
	this.blur();
	return false;
	});
}
function vthdi_show(caption, url, imageGroup, divName) {
    if ($.browser.opera) {
        /*document.getElementById('tour').style.display  = 'none';*/
        document.getElementById('tour').style.visibility = 'hidden';
    }
	/*var isIE = navigator.appName.indexOf("Microsoft") != -1;
	if(isIE == true){
	document.getElementById('tour').style.width = '1px';
	document.getElementById('tour').style.height = '1px';
	}
	var is_Win = navigator.platform.toLowerCase().indexOf('win') > -1; 
	var is_safariWin = navigator.userAgent.toLowerCase().indexOf('safari') > -1; 
	if(is_Win == true && is_safariWin == true){
	document.getElementById('tour').style.width  = '1px';
	document.getElementById('tour').style.height  = '1px';
	}*/
	document.getElementById('tour').style.width  = '1px';
	document.getElementById('tour').style.height  = '1px';
	try {
		if (typeof document.body.style.maxHeight === "undefined") {
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("IDHTV_HideSelect") === null) {
				$("body").append("<iframe id='IDHTV_HideSelect'></iframe><div id='IDHTV_overlay'></div><div id='IDHTV_window'></div>");
				$("#IDHTV_overlay").click(vthdi_remove);
			}
		}else{
			if(document.getElementById("IDHTV_overlay") === null){
				$("body").append("<div id='IDHTV_overlay'></div><div id='IDHTV_window'></div>");
				$("#IDHTV_overlay").click(vthdi_remove);
			}
		}
		
		if(vthdi_detectMacXFF()){
			$("#IDHTV_overlay").addClass("IDHTV_overlayMacFFBGHack");
		}else{
			$("#IDHTV_overlay").addClass("IDHTV_overlayBG");
		}
		
		if(caption===null){caption="";}
			$("body").append("<div id='IDHTV_load'></div>");
		$('#IDHTV_load').show();
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ 
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){
				
			IDHTV_PrevCaption = "";
			IDHTV_PrevURL = "";
			IDHTV_PrevHTML = "";
			IDHTV_NextCaption = "";
			IDHTV_NextURL = "";
			IDHTV_NextHTML = "";
			IDHTV_imageCount = "";
			IDHTV_FoundURL = false;
			if(imageGroup){
				IDHTV_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (IDHTV_Counter = 0; ((IDHTV_Counter < IDHTV_TempArray.length) && (IDHTV_NextHTML === "")); IDHTV_Counter++) {
					var urlTypeTemp = IDHTV_TempArray[IDHTV_Counter].href.toLowerCase().match(urlString);
						if (!(IDHTV_TempArray[IDHTV_Counter].href == url)) {						
							if (IDHTV_FoundURL) {
								IDHTV_NextCaption = IDHTV_TempArray[IDHTV_Counter].title;
								IDHTV_NextURL = IDHTV_TempArray[IDHTV_Counter].href;
								IDHTV_NextHTML = "<span id='IDHTV_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								IDHTV_PrevCaption = IDHTV_TempArray[IDHTV_Counter].title;
								IDHTV_PrevURL = IDHTV_TempArray[IDHTV_Counter].href;
								IDHTV_PrevHTML = "<span id='IDHTV_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							IDHTV_FoundURL = true;
							IDHTV_imageCount = "Image " + (IDHTV_Counter + 1) +" of "+ (IDHTV_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
			var pagesize = vthdi_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;
				}
			}
			IDHTV_WIDTH = imageWidth + 30;
			IDHTV_HEIGHT = imageHeight + 60;
			$("#IDHTV_window").append("<a href='' id='IDHTV_ImageOff' title='Close'><img id='IDHTV_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='IDHTV_caption'>"+caption+"<div id='IDHTV_secondLine'>" + IDHTV_imageCount + IDHTV_PrevHTML + IDHTV_NextHTML + "</div></div><div id='IDHTV_closeWindow'><a href='#' id='IDHTV_closeWindowButton' title='Close'>close</a> or Esc Key</div>"); 		
			
			$("#IDHTV_closeWindowButton").click(vthdi_remove);
			
			if (!(IDHTV_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#IDHTV_window").remove();
					$("body").append("<div id='IDHTV_window'></div>");
					vthdi_show(IDHTV_PrevCaption, IDHTV_PrevURL, imageGroup);
					return false;	
				}
				$("#IDHTV_prev").click(goPrev);
			}
			
			if (!(IDHTV_NextHTML === "")) {		
				function goNext(){
					$("#IDHTV_window").remove();
					$("body").append("<div id='IDHTV_window'></div>");
					vthdi_show(IDHTV_NextCaption, IDHTV_NextURL, imageGroup);				
					return false;	
				}
				$("#IDHTV_next").click(goNext);
						}
			document.onkeydown = function(e){ 	
				if (e == null) {
					keycode = event.keyCode;
				} else { 
					keycode = e.which;
				}
				if(keycode == 27){ 
					vthdi_remove();
				} else if(keycode == 190){
					if(!(IDHTV_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ 
					if(!(IDHTV_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			vthdi_position();
			$("#IDHTV_load").remove();
			$("#IDHTV_ImageOff").click(vthdi_remove);
			$("#IDHTV_window").css({display:"block"});
			};
			
			imgPreloader.src = url;
		}else{
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = vthdi_parseQuery( queryString );
			IDHTV_WIDTH = (params['width']*1) + 30 || 630; 
			IDHTV_HEIGHT = (params['height']*1) + 40 || 440; 
			ajaxContentW = IDHTV_WIDTH - 30;
			ajaxContentH = IDHTV_HEIGHT - 45;
			
			if(url.indexOf('IDHTV_iframe') != -1){	
					urlNoQuery = url.split('IDHTV_');
					$("#IDHTV_iframeContent").remove();
					if(params['modal'] != "true"){
												$("#IDHTV_window").append("<iframe allowtransparency='true' frameborder='0' scrolling = 'no' marginwidth='0' marginheight='0' vspace ='0' hspace='0' src='"+urlNoQuery[0]+"' id='IDHTV_iframeContent' name='IDHTV_iframeContent"+Math.round(Math.random()*1000)+"' onload='vthdi_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' ></iframe>");
						}else{
					$("#IDHTV_overlay").unbind();
						$("#IDHTV_window").append("<iframe allowtransparency='true' frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='IDHTV_iframeContent' name='IDHTV_iframeContent"+Math.round(Math.random()*1000)+"' onload='vthdi_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");

					}
			}else{
					if($("#IDHTV_window").css("display") != "block"){
						if(params['modal'] != "true"){
						$("#IDHTV_window").append("<div id='IDHTV_title'><div id='IDHTV_ajaxWindowTitle'>"+caption+"</div><div id='IDHTV_closeAjaxWindow'><a href='#' id='IDHTV_closeWindowButton'>close</a> or Esc Key</div></div><div id='IDHTV_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{
						$("#IDHTV_overlay").unbind();
						$("#IDHTV_window").append("<div id='IDHTV_ajaxContent' class='IDHTV_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{
						$("#IDHTV_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#IDHTV_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#IDHTV_ajaxContent")[0].scrollTop = 0;
						$("#IDHTV_ajaxWindowTitle").html(caption);
					}
			}					
			$("#IDHTV_closeWindowButton").click(vthdi_remove);
			if(url.indexOf('IDHTV_inline') != -1){	
					$("#IDHTV_ajaxContent").append($('#' + params['inlineId']).children());
					$("#IDHTV_window").unload(function () {
						$('#' + params['inlineId']).append( $("#IDHTV_ajaxContent").children() ); 
					});
					vthdi_position();
					$("#IDHTV_load").remove();
					$("#IDHTV_window").css({display:"block"}); 
				}else if(url.indexOf('IDHTV_iframe') != -1){
					vthdi_position();
					if($.browser.safari){
						$("#IDHTV_load").remove();
						$("#IDHTV_window").css({display:"block"});
					}
				}else{
					$("#IDHTV_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){
						vthdi_position();
						$("#IDHTV_load").remove();
						$("#IDHTV_window").css({display:"block"});
					});
				}
			
		}
		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { 
					keycode = event.keyCode;
				} else { 
					keycode = e.which;
				}
				if(keycode == 27){ 
					vthdi_remove();
				}	
			};
		}
		
	} catch(e) {
	}
}
function vthdi_showIframe(){
	$("#IDHTV_load").remove();
	$("#IDHTV_window").css({display:"block"});
}
function vthdi_remove(divName, nt) {
/*	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; 
	if(is_chrome == true){
	document.getElementById('flashcontainer').style.visibility = 'visible';
	}*/
	
	
/*	document.getElementById('hider').style.visibility = 'hidden';
	document.getElementById(divName).style.visibility = 'visible';
	document.getElementById(divName).style.display = 'block';*/
	/* amends by m */
	/*var isIE = navigator.appName.indexOf("Microsoft") != -1;
	if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
		getFlashMovie("prem6_tour").tourPlay();
		window["prem6_tour"].tourPlay();
   }
   else {
       return document[movieName]
	   getFlashMovie("prem6_tour").tourPlay(); 
	   document["prem6_tour"].tourPlay();
   }*/
 	$("#IDHTV_imageOff").unbind("click");
	$("#IDHTV_closeWindowButton").unbind("click");
	$("#IDHTV_window").fadeOut("fast",function(){$('#IDHTV_window,#IDHTV_overlay,#IDHTV_HideSelect').trigger("unload").unbind().remove();});
	$("#IDHTV_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	
	self.parent.reStartTour(nt);

	return false;
}
function vthdi_position() {
$("#IDHTV_window").css({marginLeft: '-' + parseInt((IDHTV_WIDTH / 2),10) + 'px', width: IDHTV_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) {
		$("#IDHTV_window").css({marginTop: '-' + parseInt((IDHTV_HEIGHT / 2),10) + 'px'});
	}
}
function vthdi_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}
   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;
   }
   return Params;
}
function vthdi_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 vthdi_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}
///
/*function reStartTour() {
	getFlashMovie("prem6_tour").tourPlay(); //_root.tPla();
}
function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }*/


