// JavaScript Document


window.onload = function(){
//flashMap("EN-US");
//flashMap("AR-AE");
//ULListEvent("menuElem");
//flashMenu();	 

//alert (document.body.offsetHeight);


resizeContentContainer();
}
function resizeContentContainer() {
	
	var cObj = document.getElementById('bodyContainer');
	var cObjCurve = document.getElementById('curveBottomRight');
	var cObjBodyCol2 = document.getElementById('bodyCol2');
		
	//var xHeight = cObj.offsetHeight; 
	//if (xHeight > 110)
	//	xHeight -= 100;
	
	//cObj.style.height = xHeight + 'px';
	//cObjCurve.style.position = "absolute";

	//alert(document.body.offsetHeight + " - " + xHeight);
	
	if((cObjBodyCol2.offsetHeight-610)> cObj.offsetHeight){
		 cObj.style.height = (cObjBodyCol2.offsetHeight - 600) + 'px'; 
		//alert(cObjBodyCol2.offsetHeight + " - " + cObj.offsetHeight);
		cObjCurve.style.position = "absolute";
	}
}


function getHost(){
	var hosturl = "" + window.location;
	var urlparts = hosturl.split("/");
	var host = "http://" + urlparts[2];
	return host;
}

function adjustBodyHeight() {
	
}

function showImage(id) {
	var masterImg = document.getElementById("fullsize");
	var thumbImg = document.getElementById(id);
	var thumbSrc =  thumbImg.src;
	//var thumbSrc2 = thumbSrc.replace(/100/,"1000"); 
	var thumbSrc2 = thumbSrc.replace("?maxsidesize=100","");
	masterImg.innerHTML = "<center><img src='" + thumbSrc2  + "' /></center>";
	
	//alert(thumbSrc2);
	blendimage(id,'fullsize', thumbSrc2, 600);
	//alert("Here");	
}


function windowopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=no, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
  return false;
}


function flashMenu(host, mID, dID, dType, hID, culture)
{
	

	var flashMapObj = document.getElementById('flashMenu');
	
	if(flashMapObj != null) {
		var swfFile;
		if(culture=="ar-AE") 
			swfFile =  "/CMSTemplates/lawandTourism/flash/LawandMenuArabic.swf?domain=" + getHost() + "&mId=" + mID + "&dId=" + dID + "&dType=" + dType + "&hId=" + hID + "&lang=ar-AE";
		else
			swfFile = "/CMSTemplates/lawandTourism/flash/LawandMenu.swf?domain=" + getHost() + "&mId=" + mID + "&dId=" + dID + "&dType=" + dType + "&hId=" + hID + "&lang=en-US";
		
		//alert(swfFile);
		
		var so = new SWFObject( swfFile, "flashmenu", "195", "385", "9", "");
		so.addParam("wmode", "transparent");
		so.write("flashMenu");
		
	}
}



function flashMenuOver(template)
{
	var flashMenuObj =document.getElementById('flashMenu');
	//if(template=="INSIDE")
	//	flashMenuObj.className = "flashMenuOverInside";
	//else
		flashMenuObj.zIndex = flashMenuObj.className = "flashMenuOver";
		
		
	//alert(template);
}

function flashMenuOut(template)
{
	var flashMenuObj =document.getElementById('flashMenu');
	//if(template=="INSIDE")
	//	flashMenuObj.className = "flashMenuInside";
	//else
		flashMenuObj.className = "flashMenu";
		
		
}


var selectedNodes = "";
function setSelected(id, hiddenListId) 
{
      var firstItem;
	  var Hid = document.getElementById(id);
      var NodeID= Hid.value;
	   
	   
	  //alert(Hid.value.length);
	  if(Hid.checked) 
	  	//alert("CHECKED");
		selectedNodes += "-" + NodeID; 
	
	   else 
		//alert("UNCHECKED");
		selectedNodes = selectedNodes.replace("-" + NodeID, "");
	 
	 document.getElementById(hiddenListId).value=selectedNodes;
	 //alert(hiddenListId);
	 
	  
}

function removeDestination(nodeID, hiddenListID) 
{
	document.getElementById('PItem' + nodeID).style.display="none";
	var hiddenListObj = document.getElementById(hiddenListID);
	//alert(hiddenListObj.value);
	
	hiddenListObj.value += "-" + nodeID;
	
	
	//alert(hiddenListId);		
}

/*function flashMenu(nodeID, culture, nodeLevel)
{
	

	var flashMapObj = document.getElementById('flashMenu');
	
	if(flashMapObj != null) {
		var swfFile;
		if(culture=="ar-AE") 
			swfFile = "/CMSTemplates/lawandTourism/flash/LawandMenuArabic.swf?nodeId=";
		else
			swfFile = "/CMSTemplates/lawandTourism/flash/LawandMenu.swf?nodeId=";
		
		
		var so = new SWFObject( swfFile + nodeID + "&culture=" + culture + "&level=" + nodeLevel, "Maptester", "350", "190", "9", "");
		so.addParam("wmode", "transparent");
		so.write("flashMenu");
		
	}
}*/


function flashBannerText(template, nodeID, host, h1, h2, p) 
{
	var bannnerObj = document.getElementById("flashBanner");
	var swfFile = host + "/CMSTemplates/lawandTourism/flash/";
	
	switch(template) {
		case "home":
			
			var so = new SWFObject( swfFile + "bannerTextHome.swf?domain=" + getHost() + "&nodeId=" + nodeID + "&h2=" + h2 + "&h1=" + h1 + "&p=" + p, "FlashBannerText", "354", "200", "9", "");
			so.addParam("wmode", "transparent");
			so.write("flashBanner");
			break;
			
		case "insideLevel":
			//alert("insideLevel");
			var so = new SWFObject( swfFile + "bannerTextInsideLevel.swf?domain=" + getHost() + "&nodeId=" + nodeID + "&h2=" + h2 + "&h1=" + h1 + "&p=" + p, "FlashBannerText", "550", "200", "9", "");
			so.addParam("wmode", "transparent");
			so.write("flashBanner");
			break;
			
		case "inside":
			//alert("insideLevel");
			var so = new SWFObject( swfFile + "bannerTextInside.swf?domain=" + getHost() + "&nodeId=" + nodeID + "&h1=" + h1 + "&h2=" + h2 + "&p=" + p, "FlashBannerText", "550", "200", "9", "");
			so.addParam("wmode", "transparent");
			so.write("flashBanner");
			break;
		
	}
}





function loadVideo(url, videoTitle, scrImg) {
	//var so = new SWFObject("../../CMSTemplates/lawandTourism/flash/VideoPlayer.swf?videourl=" + url + "&title=" + videoTitle, "videoPlayer", "448", "336", "9", "");
	
	scrImg = "&scrImg=" + scrImg;

	//alert("Title=" + videoTitle + " URL=" + url + "image=" + scrImg  );

		
	var so = new SWFObject("../../CMSTemplates/lawandTourism/flash/VideoPlayer.swf?videourl=" + url + "&title=" + videoTitle + scrImg, "videoPlayer", "448", "336", "9", "");

	so.addParam("wmode", "transparent");
	so.addParam("allowFullScreen", "true");
	so.addParam("allowScriptAccess", "sameDomain"); 
	so.write("videoContainer");
	
}

function flashWeather()
{
	//alert("Hello");
	var flashWeatherObj = document.getElementById('flashWeather');
	
	alert(flashWeatherObj);
	
	if(flashWeatherObj != null) {
		var so = new SWFObject("/CMSTemplates/lawandTourism/flash/WeatherFeed.swf", "Weather", "190", "70", "9", "");
		
		
		so.addParam("wmode", "transparent");
		so.write("flashWeather");
		
	}
		
}

function flashMap(lang) 
{
	var flashMapObj = document.getElementById('mapHolder');
	
	//alert(getHost());
	
	if(flashMapObj != null) {
		if(lang=="AR-AE")
			var so = new SWFObject("/CMSTemplates/lawandTourism/flash/LawandMap_Australia_Arabic.swf", "Map", "188", "152", "9", "");
		else
			var so = new SWFObject("/CMSTemplates/lawandTourism/flash/LawandMap.swf", "Map", "188", "200", "9", "");
			
		so.addParam("wmode", "transparent");
		so.write("mapHolder");
		
	}	
}


function toggleMenu(id) {
	
	var menuObj=document.getElementById(id);
		
	if(menuObj.className=="hide" || menuObj.className=="CMSListMenuUL" || menuObj.className=="" || menuObj.className==null )
		menuObj.className="show";
	else
		menuObj.className="hide";
}

function hideMenu(id) {
	var menuObj=document.getElementById(id);

	menuObj.className="hide";		
}



var subNavCount = 1;
var subNavPrefix = "subNav";

//Menu list mouse event    
function ULListEvent(id)
{
    ulObj = document.getElementById(id);
	ulObj.onmouseout = function() { this.className="hide"; }
	ulObj.onmouseover = function() { this.className="show"; }
    if(ulObj != null)
    {    
        var ulObjNodes = ulObj.childNodes;    
        for(var count=0; count < ulObjNodes.length; count++)
        {    
            if(ulObjNodes[count].nodeName == "LI")
            {
                ulObjNodes[count].onmouseover = function()
                    {                                    
                        if(id.indexOf(subNavPrefix) > -1 )
                        {
                            this.className="over";                     
                        }
                        else
                        {
                            this.className = "over";
                        }
                    }
                ulObjNodes[count].onmouseout = function()
                    {
                        if(id.indexOf(subNavPrefix) > -1 )
                        {
                            this.className="out";
                        }
                        else
                        {
                            this.className = "out";
                        }
                    }
                    
                if(ulObjNodes[count].childNodes.length > 0)
                {
                   ulObjNodesChildNodes = ulObjNodes[count].childNodes;
                   for(var count2=0; count2 < ulObjNodesChildNodes.length; count2++)
                   {
                        if(ulObjNodesChildNodes[count2].nodeName == "UL")
                        {
                           ulObjNodesChildNodes[count2].id=subNavPrefix + subNavCount;
                           subNavCount++;
                           ULListEvent(ulObjNodesChildNodes[count2].id);
                        }
                   }               
                }
            }
        }
    }        
}


var IMGsrc = "";
var mainImgObj;
var imgLoader;
var cntrY=0;

function loadImage(src, imgdescription, hiddenNodeID)
{
	IMGsrc = src;
	var pic=new Image();
	pic.src=IMGsrc; 
	
	mainImgObj = parent.document.getElementById('galleryMainImage');
	imgLoader = parent.document.getElementById('imgLoader');
	descObj = parent.document.getElementById("imgDescription");	
	hiddenObj = parent.document.getElementById("hiddenNodeID");	

	//alert(imgdescription);
	descObj.innerHTML = imgdescription;
	hiddenObj.innerHTML = hiddenNodeID;
	
	mainImgObj.src = "../../CMSTemplates/lawandTourism/css/images/transparent.gif"
	//mainImgObj.src = "../../CMSTemplates/lawandTourism/css/images/loading_image.gif"
	mainImgObj.width="600";
	cntrY=0;
	mainImgObj.style.marginTop = "0px";
	mainImgObj.style.marginLeft = "0px";
	imgLoader.style.display = "block"
		
	if(pic.complete) donePic()
	else pic.onload= donePic;	
}

function donePic()
{
	cntrY=0;
	imgLoader.style.display="none";

	blendimage('MainImage','galleryMainImage', IMGsrc, 300);

}

/* BEGIN IMAGE TOOLBAR */
function magnifyIn(id, zoom) 
{
		var xw;
		var imgObj = document.getElementById(id);
		//alert (imgObj.width); 
		xw =  imgObj.width + parseInt(zoom);
		imgObj.width = xw;
		//imgObj.height = "auto";
		//alert(xw);
}

function magnifyOut(id, zoom) 
{
		var xw;
		var imgObj = document.getElementById(id);
		//alert (imgObj.width); 
		xw =  imgObj.width - parseInt(zoom);
		imgObj.width = xw;
		//imgObj.height = "auto";
		//alert(xw);
}


function moveUp(id, zoom) 
{
		var y=0;
		var imgObj = document.getElementById(id);
		y = parseInt(imgObj.style.marginTop) - parseInt(zoom);
		//alert(imgObj.style.marginTop);
		imgObj.style.marginTop = y + "px";
}

function moveDown(id, zoom) 
{
		var y=0;
		var imgObj = document.getElementById(id);
		y = parseInt(imgObj.style.marginTop) + parseInt(zoom);
		//alert(imgObj.style.marginTop);
		imgObj.style.marginTop = y + "px";
}


function moveLeft(id, zoom) 
{
		var x=0;
		var imgObj = document.getElementById(id);
		x = parseInt(imgObj.style.marginLeft) - parseInt(zoom);
		imgObj.style.marginLeft = x + "px";
}

function moveRight(id, zoom) 
{
		var x=0;
		var imgObj = document.getElementById(id);
		x = parseInt(imgObj.style.marginLeft) + parseInt(zoom);
		imgObj.style.marginLeft = x + "px";
}


function mailPostcard(url) 
{
	
	var nodeID = document.getElementById("hiddenNodeID").innerHTML;	
	if(nodeID.length==0)
		alert("No Image Selected");
	else
		myLightWindow.activateWindow({href:'/postcardMail.aspx?imgNodeID=' + nodeID, title: 'Send Postcard', height: 200, width:400})
}

/* END IMAGE TOOLBAR */


/* BEGIN FADING EFFECT */
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = parent.document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(parent.document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	//parent.document.getElementById(divid).style.backgroundImage = "url(" + parent.document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	parent.document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(parent.document.getElementById(id).style.opacity < 100) {
		currentOpac = parent.document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

/* END FADING EFFECT  */








