var activeexpander;
var globaldynhtml;
var toggleShow = false;
var multilinetext = false;

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: 'galleryimage',
	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 'sendtomelink':
			return false;
		break;
		
		case 'loginlink':
			return false;
		break;
		
		case 'dynhtmllink':
			return false;
		break;
		
		case 'directionslink':
			return false;
		break;
		
		case 'spinlink':
			return false;
		break;
		
		case 'dmalink':
			return false;
		break;
	}
		
}


function closeactiveexpander(){
	try{
		var thisexpander = hs.getExpander();
		thisexpander.close();
	}catch(err){
		//No Action	
	}
}
		
		
function highslidecontrol(panel, hswidth, hsheight){
	
	if(!hswidth){
		hswidth = '500';
	}
	
	if(!hsheight){
		hsheight = '250';
	}
	
	switch (panel){
		case 'tbinfopane':
			var imagetag=document.getElementById('tbinfopaneanchor');
			hs.htmlExpand(imagetag, { contentId: 'tbinfopane', align: 'center', width: 600, height: 450, dimmingOpacity: 0.75 } );
		break;
		
		case 'joincommunity':
			var imagetag=document.getElementById('joincommunitylink');
			hs.htmlExpand(imagetag, { contentId: 'joincommunity', align: 'center', width: 650, height: 270, dimmingOpacity: 0.75 } );
		break;
		
		case 'joincommunityoff':
			var imagetag=document.getElementById('joincommunity');
			hs.close(imagetag);
		break;
		
		case 'directions':
			var imagetag=document.getElementById('directionslink');
			hs.htmlExpand(imagetag, { contentId: 'directionspanel', align: 'center'} );
		break;
		
		case 'directionsoff':
			var imagetag=document.getElementById('directionspanel');
			hs.close(imagetag);
		break;
		
		case 'animadir':
			var imagetag=document.getElementById('animadirlink');
			hs.htmlExpand(imagetag, { contentId: 'animadir', align: 'center', width: 300, height: 250 } );
		break;
		
		case 'sendtome':
			var imagetag=document.getElementById('sendtomelink');
			hs.htmlExpand(imagetag, { contentId: 'sendtomepanel', align: 'center', width: 600, height: 300, minWidth: 550, minheight: 300, dimmingOpacity: 0.75 } );
		break;
		
		case 'sendtomeoff':
			var imagetag=document.getElementById('sendtomepanel');
			hs.close(imagetag);
		break;
		
		case 'coupon':
			var imagetag=document.getElementById('couponlink');
			hs.htmlExpand(imagetag, { contentId: 'couponpanel', align: 'center', width: 700, height: 600, dimmingOpacity: 0.75 } );
		break;
		
		case 'couponoff':
			var imagetag=document.getElementById('couponpanel');
			hs.close(imagetag);
		break;
		
		case '3dscene':
			var scenepage='/viewpoint/3dscene.html';
			var imagetag=document.getElementById('scenelink');
			imagetag.href=scenepage;
			imagetag.onclick = function() {return hs.htmlExpand(imagetag, { objectType: 'iframe', contentId:'scenepanel', preserveContent: false, align: 'center' } )};
			imagetag.onclick();
		break;
		
		case '3dsceneoff':
			var imagetag=document.getElementById('scenelink');
			hs.close(imagetag);
		break;
		
		case 'login':
			document.getElementById("logginerror").innerHTML='';
			var imagetag=document.getElementById('loginlink');
			hs.htmlExpand(imagetag, { contentId: 'loginpanel', align: 'center', dimmingOpacity: 0.75 } );
		break;
		
		case 'loginoff':
			var imagetag=document.getElementById('loginpanel');
			hs.close(imagetag);
		break;
		
		case 'dynhtmloff':
			document.getElementById('dynhtml_content').innerHTML='';
			var imagetag=document.getElementById('hs_dynhtml');
			hs.close(imagetag);
		break;
		
		case 'pano':
			var imagetag=document.getElementById('panolink');
			hs.htmlExpand(imagetag, { contentId: 'panopanel', align: 'center' } );
		break;
		
		case 'panooff':
			var imagetag=document.getElementById('panopanel');
			hs.close(imagetag);
		break;
		
	}
	
}

function opendma(dmauser, hstitle){
	
	var contentform;
	var imagetag = document.getElementById('dmalink');
	getwinsize();
	var hswidth = (windowwidth-(windowwidth/10));
	var hsheight = (windowheight-(windowheight/10));
	
	try{
		document.getElementById('dmatitle').innerHTML = hstitle;
	}catch(err){
		//NO ACTION	
	}

		contentform='http://www.cplanet.com/dma.aspx?name='+dmauser;
			
		imagetag.href=contentform;
		imagetag.onclick = function() {return hs.htmlExpand(imagetag, { objectType: 'iframe', contentId:'dmapanel', preserveContent: false, align: 'center', width: hswidth, height: hsheight, objectHeight: hsheight, dimmingOpacity: 0.75 } )};
		imagetag.onclick();

}

function open3dscene(scene, motionmodel){
	
	var contentform;
	var imagetag = document.getElementById('dmalink');
	getwinsize();
	var hswidth = (windowwidth-(windowwidth/10));
	var hsheight = (windowheight-(windowheight/10));
	
//		switch (dmauser){
//			
//			case 'stayinmanistee':
//				contentform='http://www.cplanet.com/dma.aspx?name=stayinmanistee';
//			break;
//			
//			
//			=
//		}

		if(motionmodel=="car"){
			contentform='http://www.cplanet.com/sceneviewer_3d.html?city='+scene+'&motion=car';
		}else{
			contentform='http://www.cplanet.com/sceneviewer_3d.html?city='+scene;
		}
			
		imagetag.href=contentform;
		imagetag.onclick = function() {return hs.htmlExpand(imagetag, { objectType: 'iframe', contentId:'dmapanel', preserveContent: false, align: 'center', width: hswidth, height: hsheight, objectHeight: hsheight, dimmingOpacity: 0.75 } )};
		imagetag.onclick();

}



function opencontrol(control){
	
	var contentform;
	var imagetag = document.getElementById('controlanchor');
	var hswidth = 550;
	var hsheight = 300;
	
		switch (control){
			
			case 'lostpassword':
				contentform='controls/lostpassword.aspx';
				highslidecontrol('loginoff');
			break;
			
			case 'destdetails':
				contentform='controls/DestDetails.aspx?destid=' + document.getElementById('HiddenDestinationID').value;
				window.location = contentform;
				return;
			break;
			
			case 'destmatrix':
				contentform='controls/destmediamatrix.aspx?destid=' + document.getElementById('HiddenDestinationID').value;
				window.location = contentform;
				return;
			break;
			
			case 'connectmenu':
				contentform='controls/connectmenu.aspx?destid=' + document.getElementById('HiddenDestinationID').value;
				window.location = contentform;
				return;
			break;
			
			case 'storefrontmenu':
				contentform='controls/storefrontmenu.aspx?destid=' + document.getElementById('HiddenDestinationID').value;
				window.location = contentform;
				return;
			break;
			
			case 'organize':
				hswidth = 750;
				hsheight = 500;
				contentform='controls/cporganizedest.aspx?destid=' + document.getElementById('HiddenFieldDestinationId').value;
				//window.location = contentform;
				//return;
			break;
			
			case 'describe':
				hswidth = 750;
				hsheight = 500;
				contentform='Content_Forms/cpinfoeditor.aspx?destid=' + document.getElementById('HiddenFieldDestinationId').value;
				//window.location = contentform;
				//return;
			break;
			
		}
			
		imagetag.href=contentform;
		imagetag.onclick = function() {return hs.htmlExpand(imagetag, { objectType: 'iframe', preserveContent: false, align: 'center', width: hswidth, height: hsheight, objectHeight: hsheight, dimmingOpacity: 0.75 } )};
		imagetag.onclick();

}

function openiframepage(iframesrc, hswidth, hsheight){
	
	var imagetag = document.getElementById('ajaxanchor');
	imagetag.href=iframesrc;
	imagetag.onclick = function() {return hs.htmlExpand(imagetag, { objectType: 'iframe', preserveContent: false, align: 'center', width: hswidth, height: hsheight } )};
	imagetag.onclick();
	
}

function closehscontrols(){
	var imagetag=document.getElementById('cpcontrolslink');
	hs.close(imagetag);
}


function highslide_dynhtml(dynhtml, hswidth, hsheight, blackout){
	//NOTE: hswidth and hsheight have to be sent as strings.
	
	document.getElementById('dynhtml_content').innerHTML = dynhtml;
	
	if(!hswidth){
		hswidth = '700';
	}
	
	if(!hsheight){
		hsheight = '600';
	}
	
	//alert(hswidth+'\n'+hsheight);
	
	var imagetag = document.getElementById('dynhtmllink');
	
	if(blackout==false){
		hs.htmlExpand(imagetag, { contentId: 'hs_dynhtml', align: 'center', width: hswidth, height: hsheight } );
	}else{
		hs.htmlExpand(imagetag, { contentId: 'hs_dynhtml', align: 'center', width: hswidth, height: hsheight,  dimmingOpacity: 0.75 } );
	}
	
}


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('ajaxanchor');
	}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 custommessage(message, htitle, hswidth, hsheight) {
	
	if(!message){
		message = globaldynhtml;	
	}
	
	if(!htitle){
		htitle = '';
	}
	
	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(!hswidth){
		hs.htmlExpand(document.getElementById('messagelink'), { maincontentText: message, headingText: hsheaderhtml, preserveContent: false, allowMultipleInstances: true });
	}else{
		hs.htmlExpand(document.getElementById('messagelink'), { maincontentText: message, headingText: hsheaderhtml, preserveContent: false, allowMultipleInstances: true, width: hswidth, height: hsheight });
	}
		
}


function displayMessage(message, htitle, hswidth, hsheight) {
	
	if(!message){
		message = globaldynhtml;	
	}
	
	if(!htitle){
		htitle = '';
	}
	
	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(!hswidth){
		hs.htmlExpand(document.getElementById('messagelink'), { maincontentText: message, headingText: hsheaderhtml, preserveContent: false, allowMultipleInstances: true });
	}else{
		hs.htmlExpand(document.getElementById('messagelink'), { maincontentText: message, headingText: hsheaderhtml, preserveContent: false, allowMultipleInstances: true, width: hswidth, height: hsheight });
	}
		
}


function displaycoupon(){

	var linkanchor = document.getElementById('supportingpageslink');
	var couponurl = 'Content_Forms/displaycoupon.aspx?destid='+destinationid;
	//alert(couponurl);
	linkanchor.href = couponurl;
	linkanchor.onclick = function() {hs.htmlExpand(linkanchor, { objectType: 'iframe', contentId:'supportingpage', preserveContent: false, align: 'center', width: 750, height: 650,  dimmingOpacity: 0.75  } )};
	linkanchor.onclick();
	
}

function closeiframe(){
	document.getElementById('framecaption').innerHTML = 'blank';
	var imagetag=document.getElementById('dynweblink');
	hs.close(imagetag);
}