var activeexpander;
var globaldynhtml;
var toggleShow = false;
var multilinetext = false;
var epmediatitle;
var epmediaanchor;

var reopendestresults;
var reopentitle;

hs.graphicsDir = '../highslide/graphics/';
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.showCredits = false; 
//hs.align = 'center';
//hs.dimmingOpacity = 0.75;

// Add the controlbar
if (hs.addSlideshow) hs.addSlideshow({
	slideshowGroup: 'flickerimages',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: true,
	overlayOptions: {
		opacity: .75,
		position: 'top center',
		hideOnMouseOut: true
	}
});

hs.skin.contentWrapper =
	'<div class="highslide-header">'+
	'</div>'+
	'<div class="highslide-body"></div>'+
	'<div class="highslide-footer"><div>'+
		'<table width="100%"><tr><td align="left"><a href="#" title="{hs.lang.closeTitle}" onclick="return hs.close(this)"><span>{hs.lang.closeText}</span></a></td>'+
		'<td align="right"><span class="highslide-resize" title="{hs.lang.resizeTitle}"><span></span></span></td></tr></table>'+
	'</div></div>';

hs.Expander.prototype.onBeforeClose = function() {
	multilinetext = false;
	document.body.focus();
}

hs.transitions = ['expand', 'crossfade'];

hs.moveText = '<img src="highslide/graphics/move.gif" border="0" />';
hs.closeText = '<img src="highslide/graphics/close.gif" border="0" />';

hs.onActivate = function() {
   var theForm = document.getElementById("form1");
   if (theForm) theForm.appendChild(hs.container);
}

hs.onDimmerClick = function() {
  return false;
}

//hs.Expander.prototype.onMouseOver = function () {
//  this.focus();
//  activeexpander=this;
//}

hs.Expander.prototype.onDrag = function (sender, e) {
	var line = "";   
	   //for (var x in e) line += x +": "+ e[x] +", ";
	//alert(e.type);
	if(sender.thumb.title=='panocontent'){
		if(e.type=='resize'){
			resizepano();
		}
	}
}

hs.Expander.prototype.printHtml = function ()
{
    var pw = window.open("about:blank", "_new");
    pw.document.open();
    pw.document.write(this.getHtmlPrintPage());
    pw.document.close();
    return false;
};


hs.Expander.prototype.getHtmlPrintPage = function()
{
    // We break the closing script tag in half to prevent
    // the HTML parser from seeing it as a part of
    // the *main* page.
    var body = hs.getElementByClass(this.innerContent, 'DIV', 'highslide-body') 
        || this.innerContent;

    return "<html>\n" +
        "<head>\n" +
        "<title>Temporary Printing Window</title>\n" +
        "<script>\n" +"function step1() {\n" +
        "  setTimeout('step2()', 10);\n" +
        "}\n" +
        "function step2() {\n" +
        "  window.print();\n" +
        "  window.close();\n" +
        "}\n" +
        "</scr" + "ipt>\n" +
        "</head>\n" +
        "<body onLoad='step1()'>\n" +
        body.innerHTML +
        "</body>\n" +
        "</html>\n";
};

hs.onKeyDown = function (sender, e) {
	var thisexpander = hs.getExpander();
	var expanderid=thisexpander.a.id;
	//alert(expanderid);
	switch (expanderid){
		case 'explorelink':
			return false;
		break;
		
		case 'mystufflink':
			return false;
		break;
		
		case 'dynhtmllink':
			return false;
		break;
		
		case 'cpcontrolslink':
			return false;
		break;
		
		case 'cpcontentlink':
			return false;
		break;
		
		case 'resultshtmllink':
			return false;
		break;
		
		case 'cpresultshtmllink':
			return false;
		break;
		
		case 'mediacontentlink':
			return false;
		break;
		
		case 'wizardlink':
			return false;
		break;
		
		case 'addresssearchlink':
			return false;
		break;
	}
		
}

function hsreflow(){
	var expander = hs.getExpander();
	expander.reflow();
}

		
		
function highslidecontrol(panel, hswidth, hsheight){
	
	if(!hswidth){
		hswidth = '500';
	}
	
	if(!hsheight){
		hsheight = '250';
	}
	
	switch (panel){
		
		case 'directions':
			var imagetag=document.getElementById('directionslink');
			hs.htmlExpand(imagetag, { contentId: 'directionspanel', targetX: 'directionslink 100px' } );
		break;
		
		case 'pano':
			var imagetag=document.getElementById('panolink');
			hs.htmlExpand(imagetag, { contentId: 'panopanel', align: 'center' } );
		break;
		
		case 'animadir':
			var imagetag=document.getElementById('animadirlink');
			hs.htmlExpand(imagetag, { contentId: 'animadir', align: 'center' } );
		break;
		
		case 'panooff':
			try{
				svp.remove();
			}catch(err){
				//No Action
			}
			closeactiveexpander();
		break;
		
		case 'destdetails':
			var imagetag=document.getElementById('destdetailslink');
			hs.htmlExpand(imagetag, { contentId: 'destdetailspanel', align: 'center', allowSizeReduction: false } );
		break;
		
	
		case 'explore':
			if(mod_searchstring){
				var imagetag=document.getElementById('explorepanel');
				
				if(userplatform != 'iphone'){
					hs.htmlExpand(imagetag, { contentId: 'exploreresults', allowMultipleInstances: false, outlineType: 'rounded-cplanetblue', targetX: 'map 70px', targetY: 'map 10px', width: 250, allowSizeReduction: true } );
				}else{
					hs.htmlExpand(imagetag, { contentId: 'exploreresults', allowMultipleInstances: false, outlineType: 'rounded-cplanetblue', targetX: 'map 70px', targetY: 'map 10px', width: 250, allowSizeReduction: false } );
				}
			
				//imagetag.reflow();
			}else{
				midnavsearchdisplay('on');
			}
		break;
		
		case 'exploreoff':
			var imagetag=document.getElementById('exploreresults');
			hs.close(imagetag);
		break;
		
		case 'resultshtml':
			var imagetag = document.getElementById('resultsanchor');
			if(userplatform != 'iphone'){
				hs.htmlExpand(imagetag, { contentId: 'resultshtmlpanel', targetX: 'map 20px', targetY: 'map 165px', width: 275, height: 350 } );
			}else{
				hs.htmlExpand(imagetag, { contentId: 'resultshtmlpanel', targetX: 'map 20px', targetY: 'map 165px', width: 275, allowSizeReduction: false } );
			}
			highslidecontrol('cpresultshtmloff');
		break;
		
		case 'cthereresultshtml':
			var imagetag = document.getElementById('resultsanchor');
			if(userplatform != 'iphone'){
				hs.htmlExpand(imagetag, { contentId: 'resultshtmlpanel', align: 'center', width: 350, height: 400 } );
			}else{
				hs.htmlExpand(imagetag, { contentId: 'resultshtmlpanel', align: 'center', width: 350, allowSizeReduction: false } );
			}
			highslidecontrol('cpresultshtmloff');
		break;
		
		case 'resultshtmlwizard':
			hswidth = '350';
			hsheight = '300';
			var imagetag=document.getElementById('resultshtmllink');
			imagetag.onclick = function() {hs.htmlExpand(imagetag, { contentId:'resultshtmlpanel', align: 'center', width: hswidth, height: hsheight, dimmingOpacity: 0.75 } )};
			imagetag.onclick();
		break;
		
		case 'resultshtmloff':
			document.getElementById("resultshtmlpanel").style.height = '350px';
			var imagetag=document.getElementById('resultshtmlpanel');
			hs.close(imagetag);
		break;
	
	
	}
	
}

function openorganizedest(){
	
	var imagetag = document.getElementById('organizedestlink');
	hswidth = 675;
	hsheight = 550;
	htitle = '<span class="cpfontheading"><i>Creating with Cplanet</i></span>';
			
	var activetourid = "";
	var activedestination;
	
	try{
		activetourid = document.getElementById('HiddenFieldTourId').value;
	}catch(err){
		//NO ACTION	
	}
	
	activedestination = document.getElementById('HiddenFieldDestinationId').value;
	
	//alert(activetourid +' , '+activedestination);
	if(activetourid != ''){
		var argstring = '?tourid='+activetourid;
		if(activedestination != ''){
			argstring += '&destid='+activedestination;
		}
		contentform='controls/cporganizedest.aspx'+argstring;
	}else{
		//alert(savedestinationid);
			if(activedestination != ''){
				//alert(savedestinationid);
				var argstring = '?destid='+activedestination;
				contentform='controls/cporganizedest.aspx'+argstring;
				//alert(contentform);
			}else{
				alert('No Destination ID Found');
			}
	}
	
	var hsheaderhtml = '<table><tr><td width="100%">'+htitle+'</td><td align="right"><img src="highslide/graphics/close.gif" onclick="closeactiveexpander()" alt="Close Panel" onmouseover="this.style.cursor=\'pointer\'" border="0" /></td></tr></table>';
		
	imagetag.href=contentform;
	imagetag.onclick = function() {return hs.htmlExpand(imagetag, { objectType: 'iframe', headingText: hsheaderhtml, preserveContent: false, align: 'center', width: hswidth, height: hsheight, objectHeight: hsheight, dimmingOpacity: 0.75 } )};
	imagetag.onclick();
}


function closeactiveexpander(){
	var thisexpander = hs.getExpander();
	thisexpander.close();
}

function highslideajax(extpage, pagesection, hsanchor, htitle, hswidth, hsheight, dimmeron){
	
	//alert(extpage+' , '+pagesection+' , '+htitle+' , '+hswidth+' , '+hsheight+' , '+dimmeron)
	
	if(!hswidth){
		hswidth = '550';
	}
	
	if(!hsheight){
		hsheight = '450';
	}
	
	var ajaxlink = extpage
	
	if(pagesection){
		ajaxlink += '#'+pagesection;
	}
	
	var hsheaderhtml = '<table><tr><td width="100%"><div class="cpfontheading" id="ajaxtitle">'+htitle+'</div></td><td align="right"><img src="highslide/graphics/close.gif" onclick="closeactiveexpander()" alt="Close Panel" onmouseover="this.style.cursor=\'pointer\'" border="0" /></td></tr></table>';
	
	if(!hsanchor){
		var imagetag = document.getElementById('wizardlink');
	}else{
		var imagetag = document.getElementById(hsanchor);
	}
	
	
	imagetag.href = ajaxlink;
	
	if(dimmeron == true){
		imagetag.onclick = function() {return hs.htmlExpand(imagetag, {  objectType: 'ajax', preserveContent: false, headingText: hsheaderhtml, align: 'center', width: hswidth, height: hsheight, dimmingOpacity: 0.75 } )};
	}else{
		imagetag.onclick = function() {return hs.htmlExpand(imagetag, {  objectType: 'ajax', preserveContent: false, headingText: hsheaderhtml, align: 'center', width: hswidth, height: hsheight } )};
	}
	
	imagetag.onclick();
	
}

function replacecreateajax(responsetext){
//	var exxxp = hs.getExpander();
//	exxxp.content.innerHTML = responsetext;
//	exxxp.reflow(responsetext);
}


function closeextajax(){
	
	var imagetag=document.getElementById('wizardlink');
	hs.close(imagetag);
	
}


function closeextajax_l2(){
	
	var imagetag=document.getElementById('wizardlink_l2');
	hs.close(imagetag);
	
}

function framewebsite(siteurl){

	var linkhtml;
	var hswidth = windowwidth - 100;
	var linkanchor = document.getElementById('dynweblink');
	
	linkhtml = '<a href="'+siteurl+'" target="_blank"><img src="globalgraphics/general/newwindow.gif" border="0" onmouseover="this.style.cursor=\'pointer\'" /></a>';
	
	var hsheaderhtml = '<table width="100%"><tr><td>'+linkhtml+'</td><td align="right"><img src="highslide/graphics/close.gif" onclick="closeactiveexpander()" alt="Close Panel" onmouseover="this.style.cursor=\'pointer\'" border="0" /></td></tr></table>';
	
	linkanchor.href=siteurl;
	linkanchor.onclick = function() {hs.htmlExpand(linkanchor, { objectType: 'iframe', headingText: hsheaderhtml, preserveContent: false, align: 'center', height: 650, minWidth: 900, objectHeight: 600 } )};
	linkanchor.onclick();
	
}


//****NOTE:  HIGHSLIDE EXT PAGE FUNCTION REQUIRES THE HIGHSLIDE FUNCTIONALITY JAVASCRIPTS INCLUDED IN THE PAGE
//****NOTE:  THE ANCHOR LINK 'extpagelink' MUST RESIDE ON THE PAGE
function highslide_extpage(page, hswidth, hsheight, blackout){

	var imagetag = document.getElementById('extpagelink');
			
	if(!hswidth){
		hswidth = '700';
	}
	
	if(!hsheight){
		hsheight = '600';
	}
	
	if(page!=''){
		imagetag.href=page;
		if(blackout==false){
			imagetag.onclick = function() {return hs.htmlExpand(imagetag, { objectType: 'iframe', preserveContent: false, objectLoadTime: 'after', align: 'center', width: hswidth, height: hsheight} )};
		}else{
			imagetag.onclick = function() {return hs.htmlExpand(imagetag, { objectType: 'iframe', preserveContent: false, objectLoadTime: 'after', align: 'center', width: hswidth, height: hsheight, dimmingOpacity: 0.75 } )};
		}
																
		imagetag.onclick();
	}
}

function turnonloading(){
	var imagetag=document.getElementById('loadinglink');
	var loadinghtml = '<div align="center"><img src="globalgraphics/resellertool/cploading.gif" /></div>';
	hs.htmlExpand(imagetag, { maincontentText: loadinghtml, preserveContent: false, width: 400, height: 400 });	
}

function turnoffloading(){
	var imagetag=document.getElementById('loadinglink');
	hs.close(imagetag);
}


function displayepmedia(responsetext, hswidth, hsheight){
	
	//turnoffloading();
	var imagetag = epmediaanchor;
	
	var hsheaderhtml = '<table width="100%"><tr><td>'+epmediatitle+'</td><td align="right"><img src="highslide/graphics/close.gif" onclick="closeactiveexpander()" alt="Close Panel" onmouseover="this.style.cursor=\'pointer\'" border="0" /></td></tr></table>';
	
	var exxxp = hs.getExpander();
	try{
		switch(exxxp.a.id){
			case 'mimageanchor':
				exxxp.content.innerHTML = responsetext;
				exxxp.headingText.innerHTML = hsheaderhtml;
			break;
			
			case 'mvideoanchor':
				exxxp.content.innerHTML = responsetext;
				exxxp.headingText.innerHTML = hsheaderhtml;
			break;
			
			default:
				hs.htmlExpand(imagetag, { maincontentText: responsetext, headingText: hsheaderhtml, preserveContent: false, width: hswidth, height: hsheight });
			break;
		}
		
	}catch(err){
		hs.htmlExpand(imagetag, { maincontentText: responsetext, headingText: hsheaderhtml, preserveContent: false, width: hswidth, height: hsheight });
	}
	
	try{
		document.getElementById("txtrisearch").value = imagesearchterm;
	}catch(err){
		//NO ACTION	
	}
		
}

function displayCPResults(message, htitle, hswidth, hsheight) {
	
	var cpanchor = document.getElementById('cpresultsanchor');
	
	if(!htitle){
		htitle = '';
	}
	
	var hsheaderhtml = '<table width="100%" bgcolor="#00218B"><tr><td>'+htitle+'</td><td align="right"><img src="highslide/graphics/close.gif" onclick="closeactiveexpander()" alt="Close Panel" onmouseover="this.style.cursor=\'pointer\'" border="0" /></td></tr></table>';
	
	var newexpander = true;
	
	try{
	
		var exxxp = hs.getExpander();
		
		if(exxxp.a.id == 'cpresultsanchor'){
			newexpander = false;
		}
	
	}catch(err){
		//NO ACTION
	}
	
	//alert(newexpander);
	if(newexpander == false){
		exxxp.content.innerHTML = message;
		exxxp.headingText.innerHTML = hsheaderhtml;
	}else{
		if(!hswidth){
			hs.htmlExpand(cpanchor, { maincontentText: message, headingText: hsheaderhtml, outlineType: 'rounded-cplanetblue', preserveContent: false, targetX: 'map 85px', targetY: 'map 135px' });
		}else{
			hs.htmlExpand(cpanchor, { maincontentText: message, headingText: hsheaderhtml, outlineType: 'rounded-cplanetblue', preserveContent: false, width: hswidth, height: hsheight, targetX: 'map 85px', targetY: 'map 135px' });
		}
	}
		
}

function displaydestresults(message, htitle){
	
	if(message){
		reopentitle = htitle;
		reopendestresults = message;
	}
	
	if(reopendestresults){
		var hsheaderhtml = '<table width="100%"><tr><td><img src="globalgraphics/general/icon_destgroup.png" /></td><td>'+reopentitle+'</td><td align="right"><img src="highslide/graphics/close.gif" onclick="closeactiveexpander()" alt="Close Panel" onmouseover="this.style.cursor=\'pointer\'" border="0" /></td></tr></table>';
	
		hs.htmlExpand(document.getElementById('destresultsanchor'), { maincontentText: reopendestresults, headingText: hsheaderhtml, outlineType: 'rounded-cplanetorange', preserveContent: false, width: 250, anchor: 'top right', allowSizeReduction: false });
	}
		
}



function displayMessage(message, htitle, hswidth, hsheight){
	
	if(!message){
		message = globaldynhtml;	
	}
	
	if(!htitle){
		htitle = '';
	}
	
	var hsheaderhtml = '<table width="100%"><tr><td>'+htitle+'</td><td align="right"><img src="highslide/graphics/close.gif" onclick="closeactiveexpander()" alt="Close Panel" onmouseover="this.style.cursor=\'pointer\'" border="0" /></td></tr></table>';
	
	if(!hswidth){
		hs.htmlExpand(document.getElementById('dynhtmllink'), { maincontentText: message, headingText: hsheaderhtml, preserveContent: false });
	}else{
		hs.htmlExpand(document.getElementById('dynhtmllink'), { maincontentText: message, headingText: hsheaderhtml, preserveContent: false, width: hswidth, height: hsheight });
	}
		
}

function dynmaichtml(newcontent) {
      //var slot = document.getElementById("dynhtmlcontent");
      //var newNode = document.createTextNode(" ...and more, ");
      //slot.appendChild(newNode);
      //slot.innerHTML=newcontent;
	var exp2 = hs.getExpander();
	exp2.body.innerHTML = newcontent;
	exp2.reflow();
}

