// $Header: $
/***************************************************************************
 * Automatic Image Popup
 * Copyright 2002 by David Schontzler | www.stilleye.com
 * Free to use under GNU General Public License as long as this message
 *  remains intact.
 * Description:  Automate your image popup windows (centered and sized)
 * URI: http://www.stilleye.com/scripts/iPop
 ***************************************************************************
 * Version: 1.0
 ***************************************************************************/
function iPop(img, w, h, ttl){
    var iPopURL = '/ipop.html' // set as location of ipop.html
    var url = iPopURL + '?' + img + (ttl ? '&' + escape(ttl) : '')
    var l = Math.round((screen.availWidth-w)/2),t=Math.round((screen.availHeight-h)/2);
    var attribs = 'width=' + w + ',height=' + h + ',left=' + l + ',top=' + t;
    var w=window.open(url, 'imgWin', attribs);
    return false;
}

function domRollover() {
	var imgTemp=new Array();
	var imgarr=document.getElementsByTagName('img');
	for (var i=0;i<imgarr.length;i++){
	if (imgarr[i].getAttribute('hsrc')){
			imgTemp[i]=new Image();
			imgTemp[i].src=imgarr[i].getAttribute('hsrc');
			imgarr[i].setAttribute('xsrc', imgarr[i].getAttribute('src'));
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.getAttribute('hsrc'))
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}
domRollover();

/****************************************************
 *	Creates and centers a popup window
 *		by LWD-hk 20030722
 ****************************************************/
function rsPopUp(url, w, h, ttl){
    var l = Math.round((screen.availWidth-w)/2),t=Math.round((screen.availHeight-h)/2);
    var attribs = 'scrollbars=yes,resizable=yes,width=' + w + ',height=' + h + ',left=' + l + ',top=' + t
    var w=window.open(url, 'newWindow', attribs);
    return false;
}
//Package fader
function slideShow(id,delay) {
	var packages=$A($$('div#'+id+'_content div.fading'));
	if( packages.length>1)
	    setTimeout(switch_slides(id,1,1,packages.length,delay*1000),delay*1000);
}
function switch_slides(id,frame, start_frame, end_frame, delay) {
    return (function() {
        Effect.Fade(id+frame);
        frame++;
        if(frame>end_frame) frame=1;
        setTimeout("Effect.Appear('"+id+frame+"');", 850);
        setTimeout(switch_slides(id,frame, start_frame, end_frame, delay),delay + 850);
    })
}
function showCatalogue(catno,catpg) {
	var s=navigator.userAgent.toLowerCase();
	var browserInfo={
			IsIE		: /*@cc_on!@*/false,
			IsIE7		: /*@cc_on!@*/false && ( parseInt( s.match( /msie (\d+)/ )[1], 10 ) >= 7 )
	};
	var w=w||1024,h=h||700;
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
	var arrayPageSize = getPageSize();
	$('overlay').style.height = arrayPageSize[1] + "px";
	new Effect.Appear('overlay', { duration: 0.0, from: 0.0, to: 0.6 	});
    var xyscroll = ( browserInfo.IsIE && !browserInfo.IsIE7 )?document.viewport.getScrollOffsets():[0,0];
	var innerH=document.viewport.getHeight(),innerW=document.viewport.getWidth();
	var pars='method=popup&no='+catno+'&pg='+catpg+'&'+Math.random(9999);
	var popup = $('popup');
	var m = new Ajax.Updater(popup, '/catalogue.cfm', {
		method: 'get',
		parameters: pars,
		onComplete: function(){
			var l=Math.round(xyscroll[0]+(innerW-w)/2),t=Math.round(xyscroll[1]+(innerH-h)/2);
			$('popup').setStyle({ top: t + "px", left: l + "px", width: w + "px", height: h + "px",cursor: 'pointer'});
			$('popup').style.position=( browserInfo.IsIE && !browserInfo.IsIE7 ) ? 'absolute' : 'fixed';
			$(popup).show();
			new Draggable(popup,{});
		}
	});
}
function showMap(id,lang,w,h) {
	var s=navigator.userAgent.toLowerCase();
	var browserInfo={
		IsIE		: /*@cc_on!@*/false,
		IsIE7		: /*@cc_on!@*/false && ( parseInt( s.match( /msie (\d+)/ )[1], 10 ) >= 7 )
	};
	var w=w||800,h=h||600;
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
    var arrayPageSize = getPageSize();
    $('overlay').style.height = arrayPageSize[1] + "px";
	new Effect.Appear('overlay', { duration: 0.0, from: 0.0, to: 0.6 	});
    var xyscroll = ( browserInfo.IsIE && !browserInfo.IsIE7 )?document.viewport.getScrollOffsets():[0,0];
	var innerH=document.viewport.getHeight(),innerW=document.viewport.getWidth();
	var pars='clientid=' + id + '&lang=' + lang + '&' + Math.random(9999);
	var popup = $('gmap');
    var m = new Ajax.Updater(popup, '/media/templates/forms/googlemap.cfm', {
        method: 'get',
        parameters: pars,
        onComplete: function(){
		var l=Math.round(xyscroll[0]+(innerW-w)/2),t=Math.round(xyscroll[1]+(innerH-h)/2);
			$('gmap').setStyle({ top: t + "px", left: l + "px", width: w + "px", height: h + "px",cursor : 'pointer'});
			$('gmap').style.position=( browserInfo.IsIE && !browserInfo.IsIE7 ) ? 'absolute' : 'fixed';
            Effect.Appear(popup,{duration:.5});
            new Draggable(popup,{});
        }
    });
}
function showVideo(oid) {
	var s=navigator.userAgent.toLowerCase();
	var browserInfo={
			IsIE		: /*@cc_on!@*/false,
			IsIE7		: /*@cc_on!@*/false && ( parseInt( s.match( /msie (\d+)/ )[1], 10 ) >= 7 )
	};
	var w=425,h=h||370;
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
	var arrayPageSize = getPageSize();
	$('overlay').style.height = arrayPageSize[1] + "px";
	new Effect.Appear('overlay', { duration: 0.0, from: 0.0, to: 0.6 	});
	var xyscroll = ( browserInfo.IsIE && !browserInfo.IsIE7 )?document.viewport.getScrollOffsets():[0,0];
	var innerH=document.viewport.getHeight(),innerW=document.viewport.getWidth();
	var pars='objectid=' + oid;
	var popup = $('popup');
	var m = new Ajax.Updater(popup, '/video.cfm', {
		method: 'get',
		parameters: pars,
		onComplete: function(){
		var l=Math.round(xyscroll[0]+(innerW-w)/2),t=Math.round(xyscroll[1]+(innerH-h)/2);
		$('popup').setStyle({ top: t + "px", left: l + "px", width: w + "px", height: h + "px",cursor : 'pointer'});
		$('popup').style.position=( browserInfo.IsIE && !browserInfo.IsIE7 ) ? 'absolute' : 'fixed';
		Effect.Appear(popup,{duration:.5});
	}
	});
}
function showInfoWin(id,method,lang,w,h,t,l) {
	var s=navigator.userAgent.toLowerCase();
	var browserInfo={
			IsIE		: /*@cc_on!@*/false,
			IsIE7		: /*@cc_on!@*/false && ( parseInt( s.match( /msie (\d+)/ )[1], 10 ) >= 7 )
	};
	var w=w||800,h=h||600;
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
	var arrayPageSize = getPageSize();
	$('overlay').style.height = arrayPageSize[1] + "px";
	new Effect.Appear('overlay', { duration: 0.0, from: 0.0, to: 0.6 	});
    var xyscroll = ( browserInfo.IsIE && !browserInfo.IsIE7 )?document.viewport.getScrollOffsets():[0,0];
	var innerH=document.viewport.getHeight(),innerW=document.viewport.getWidth();
	var pars='objectid=' + id + '&method=' + method + '&lang=' + lang + '&' + Math.random(9999);
	var popup = $('popup');
	var m = new Ajax.Updater(popup, '/popup.cfm', {
		method: 'get',
		parameters: pars,
		onComplete: function(){
			var l=Math.round(xyscroll[0]+(innerW-w)/2),t=Math.round(xyscroll[1]+(innerH-h)/2);
			$('popup').setStyle({ top: t + "px", left: l + "px", width: w + "px", height: h + "px",cursor : 'pointer'});
			$('popup').style.position=( browserInfo.IsIE && !browserInfo.IsIE7 ) ? 'absolute' : 'fixed';
            Effect.Appear(popup,{duration:.5});
			new Draggable(popup,{});
		}
	});
}
function hideMap() {
    Effect.BlindUp('gmap', {
        duration: 0.3
    });
    Element.hide('overlay');
	document.body.scroll='auto';
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
}
function hideInfoWin() {
	Effect.BlindUp('popup', {
		duration: 0.3
	});
	Element.hide('overlay');
	document.body.scroll='auto';
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
}
function getPageSize() {
    var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth)
			windowWidth = document.documentElement.clientWidth; 
		else
			windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	pageHeight=(yScroll < windowHeight)?windowHeight:yScroll;
	// for small pages with total width less then width of the viewport
	pageWidth=(xScroll < windowWidth)?xScroll:windowWidth;
	return [pageWidth,pageHeight];
}

function showLayer(e,c) {
	var e=e||event,et=Event.findElement(e, 'LI');
	var xyPos=$(et).cumulativeOffset(),xyBasePos=$('horizontal_carousel').cumulativeOffset();
	var l=Math.min(385, xyPos.left-xyBasePos.left),t=xyPos.top+50;
	s = $('country_'+c);
	$('countrydetails').update(s.innerHTML).setStyle({left:l+"px",top:t+"px"}).show();
	Event.observe(document,'mouseover',function(ev) {
		var ev=ev||event,et=Event.findElement(ev, 'DIV');
		if(et&&et.hasClassName('moarea'))
			return; // currenttarget is div with class mouseoverarea
		var elt = $(Event.element(ev)).up('.moarea'); // search for upper target div with class mouseoverarea
		if(elt&&elt.hasClassName('moarea'))
				return;
		$('countrydetails').hide();
	});
}

/****************************************************
*	Add Site to Favorits:
*		by LWD-sb 20051019
****************************************************/
function addBookmark(title) {

	var url = document.location.href;
	var foo = url.split('?');
	url = foo[0];
	
	if (window.sidebar)
		window.sidebar.addPanel(title, url,""); 
	else if( document.all )
		window.external.AddFavorite( url, title);
	return;
}