/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
/* -----------------------------------------------
  Image Preloader - v.1.1
  (c) 2007 http://www.haan.net
  You may use this script but please leave the credits on top intact.
  Please inform us of any improvements made.
  When useful, we will add your credits.
------------------------------------------------ */
function preload() {
 	var brochure = new Array();
 	var pics = preload.arguments;
 	var dir = './images/navigation/' // path to images
 	for (i=0;i<pics.length;i++) {
  		brochure[i] = new Image();
  		brochure[i].src = dir + pics[i] + '.gif'; // change file extension, if necessary.
 		// uncomment next line for testing; click OK to continue loop and cancel to break
 		//if(i==0)
		//	if(!confirm(brochure[i].src)) break;
 	}
}

// call the function with the list of images (unique part of names)
// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(function() {
	chkSlideShow();
	galPreload();	
});
function chkSlideShow(){
	if ( typeof( window[ 'slideShow_preLoad' ] ) != "undefined" ) {
	//definded array of image for slideshow()
	   runSlideShow();  
	}
}
/* Gallery Preload */
function galPreload() {
	
	if ( typeof( window[ 'OneLinks' ] ) != "undefined" ) {
		OneOptionList();
	}//end if not undefined OneLinks Argument
}//end function galPreload

/*------ javascript function ------*/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function jumpBox(URL){
  window.location.href = URL;
}
function popCode(URL) {
  if(URL!=2){
    window.open(URL, "Code","resizable=yes,scrollbars=yes,toolbar=no,status=no,height=600,width=800");			
  }
}

/* Slide show */
function runSlideShow() {
	if (document.all) {
		document.images.SlideShow.style.filter="blendTrans(duration=2)";
		document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
		document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = slideShow_preLoad[j].src;
	if (document.all) {
		document.images.SlideShow.filters.blendTrans.Play();
	}
	j = j + 1;
	if (j > (p - 1)) j = 0;
	t = setTimeout('runSlideShow()', slideShowSpeed);
}
//Hides the layer onload 'loading bar'
function hideIt(){
		changeObjectVisibility('divLoadCont', 'hidden');
}
function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
		return getObjNN4(document,objectId);
	} else {
		//alert('getstyle false');
		return false;
	}
} 
function changeObjectVisibility(objectId, newVisibility) {
    var styleObject = getStyleObject(objectId, document);
    if(styleObject) {
		styleObject.visibility = newVisibility;
		return true;
    } else {
		//alert('setVisibility false');
		return false;
    }
} 
/* bookmark function for all IE , Firefox , opera */
 function bookMarkUs(url,title) {
// title 		- "Webpage Title"; 
// Blogger 		- Replace with <$BlogItemTitle$> 
// MovableType 	- Replace with <$MTEntryTitle$>
// url 			- "Webpage URL";
// Blogger 		- Replace with <$BlogItemPermalinkURL$> 
// MovableType 	- Replace with <$MTEntryPermalink$>
// WordPress 	- <?php bloginfo('url'); ?>
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
		 
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); 
		
	} else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
	
 }
/* Make loading bar element for hideIt();*/
function makeLoadingBar(){
	document.write("<div id=\"divLoadCont\"><img src=\"./images/loading_bar.gif\" width=\"199\" height=\"64\" alt=\"loading content\" title=\"loading content\" /><\/div>");
}
/*=========================================================
       Gallery Slide Show Function
=========================================================*/
var galItem = new Array();
var reloadTime = 5000; //1 second
// gennerate option list for select box
function OneOptionList(){
	//var sel_elem  = document.Oneslideform.Oneslide; 	//selectbox element
	var img_elem  = document.getElementById("oneshow"); //image element
	var desc_elem = document.getElementById("onetext"); //text description element
	
	
	//make all option list form array element
	for(i=0;i<OneLinks.length;i++){
		//sel_elem.options[i] = new Option('Image '+(i+1),OneLinks[i]);
		galItem[i] 			= new Image(); //load image
		galItem[i].src 		= OneLinks[i];
	}
	
	//sel_elem.selectedIndex 	= Onecurrent;				//set default for selected optoion
	var index 				= Onecurrent;//sel_elem.selectedIndex;
	img_elem.src 			= galItem[index].src; 	//set image path
	img_elem.alt 			= OneTitle[index]; 			//set alt for image
	img_elem.title 			= OneTitle[index]; 			//set title for image
	desc_elem.innerHTML		= OneDescribe[index]; 		//set text
	//alert('optionlsit');
	//start automatic	
	
	var img_ok=isImageOk(document.getElementById("oneshow"));
	if(!img_ok) {
		window.setTimeout(OneReload, reloadTime, Onecurrent, 'Oneap|" Start "');
	}else{
		//eval('Oneap();');
		Oneap(' Start ');
	}
	
}//end function OneOptionList()
//Click Next Button
function Onenext() { 
	if (document.Oneslideform.Oneslide[Onecurrent+1]) {
		effektberechnen();
		var opt_text=OneTitle[Onecurrent+1];
		document.getElementById("oneshow").src = galItem[Onecurrent+1].src;
		document.getElementById("oneshow").width = galItem[Onecurrent+1].width;
		document.getElementById("oneshow").height = galItem[Onecurrent+1].height;
		adjustImageSize(document.getElementById("oneshow"),OneMaxW,OneMaxH);
		document.getElementById("oneshow").alt = opt_text;
		document.getElementById("oneshow").title = opt_text;
		document.getElementById("onetext").innerHTML=OneDescribe[Onecurrent+1];
		
		effektzeigen();
		//document.Oneslideform.Oneslide.selectedIndex = ++Onecurrent;
		
		var img_ok=isImageOk(document.getElementById("oneshow"));
		if(!img_ok) window.setTimeout(OneReload, reloadTime, Onecurrent, 'onenext');
		
	}
	else {Onefirst(); }
	
	
}
// Click Back Button
function Oneprevious() {
	if (Onecurrent-1 >= 0) {
		effektberechnen();
		var opt_text=OneTitle[Onecurrent-1];
		document.getElementById("oneshow").src = galItem[Onecurrent-1].src;
		document.getElementById("oneshow").width = galItem[Onecurrent-1].width;
		document.getElementById("oneshow").height = galItem[Onecurrent-1].height;
		adjustImageSize(document.getElementById("oneshow"),OneMaxW,OneMaxH);
		document.getElementById("oneshow").alt = opt_text;
		document.getElementById("oneshow").title = opt_text;
		document.getElementById("onetext").innerHTML=OneDescribe[Onecurrent-1];
		effektzeigen()
		//document.Oneslideform.Oneslide.selectedIndex = --Onecurrent;
	}
	else Onelast();
}
// Move to First Element 
function Onefirst() {
	Onecurrent = 0;
	effektberechnen();
	document.getElementById("oneshow").src = galItem[0].src;
	document.getElementById("oneshow").width = galItem[0].width;
	document.getElementById("oneshow").height = galItem[0].height;
	adjustImageSize(document.getElementById("oneshow"),OneMaxW,OneMaxH);
	var opt_text = OneTitle[0];
	document.getElementById("oneshow").alt = opt_text;
	document.getElementById("oneshow").title = opt_text;
	document.getElementById("onetext").innerHTML = OneDescribe[0];
	effektzeigen()
	//document.Oneslideform.Oneslide.selectedIndex = 0;
}
// Move to Last Element
function Onelast() {
	Onecurrent = OneLinks.length - 1;//document.Oneslideform.Oneslide.length-1;
	effektberechnen()
	document.getElementById("oneshow").src = galItem[Onecurrent].src;
	document.getElementById("oneshow").width = galItem[Onecurrent].width;
	document.getElementById("oneshow").height = galItem[Onecurrent].height;
	adjustImageSize(document.getElementById("oneshow"),OneMaxW,OneMaxH);
	var opt_text=OneTitle[Onecurrent];
	document.getElementById("oneshow").alt = opt_text;
	document.getElementById("oneshow").title = opt_text;
	document.getElementById("onetext").innerHTML = OneDescribe[Onecurrent];
	effektzeigen()
	//document.Oneslideform.Oneslide.selectedIndex = Onecurrent;
}
// Click Button for Start/Stop Slide show and change Text in Button 
function Oneap(text) {
	text = (typeof(text) != "undefined")? text: ' start ';
	document.Oneslideform.Oneslidebutton.value = (text == " Stop ") ? " Start " : " Stop ";
	Onerotate();
}
// Move to Selected Element 
function Onechange() {
	//Onecurrent = document.Oneslideform.Oneslide.selectedIndex;
	effektberechnen()
	document.getElementById("oneshow").src = galItem[Onecurrent].src;
	document.getElementById("oneshow").width = galItem[Onecurrent].width;
	document.getElementById("oneshow").height = galItem[Onecurrent].height;
	adjustImageSize(document.getElementById("oneshow"),OneMaxW,OneMaxH);
	var opt_text=OneTitle[Onecurrent];
	document.getElementById("oneshow").alt = opt_text;
	document.getElementById("oneshow").title = opt_text;
	document.getElementById("onetext").innerHTML=OneDescribe[Onecurrent];
	effektzeigen()
}
// Slide Show process 
function Onerotate() {

	if (document.Oneslideform.Oneslidebutton.value == " Stop ") {
		Onecurrent = (Onecurrent == galItem.length -1/*document.Oneslideform.Oneslide.length-1*/) ? 0 : Onecurrent+1;
		
		effektberechnen()
		document.getElementById("oneshow").src = galItem[Onecurrent].src;
		document.getElementById("oneshow").width = galItem[Onecurrent].width;
		document.getElementById("oneshow").height = galItem[Onecurrent].height;
		adjustImageSize(document.getElementById("oneshow"),OneMaxW,OneMaxH);
		var opt_text=OneTitle[Onecurrent];
		document.getElementById("oneshow").alt = opt_text;
		document.getElementById("oneshow").title = opt_text;
		document.getElementById("onetext").innerHTML=OneDescribe[Onecurrent];
		effektzeigen()
		//document.Oneslideform.Oneslide.selectedIndex = Onecurrent;
		var img_ok=isImageOk(document.getElementById("oneshow"));
		if(!img_ok) Onecurrent-=1;
		window.setTimeout("Onerotate()", Onerotate_delay);
	}
}
function Onetransport(){
	Onenext();
}
function OneReload(img_index, caller_func){
//	alert('caller: '+caller_func +', reload:' + img_index);
 	reImg = new Image();
	reImg.src = OneLinks[img_index];
	var opt_text=OneTitle[img_index];
	document.getElementById("oneshow").src = reImg.src;
	document.getElementById("oneshow").width = reImg.width;
	document.getElementById("oneshow").height = reImg.height;
	adjustImageSize(document.getElementById("oneshow"),OneMaxW,OneMaxH);
	document.getElementById("oneshow").alt = opt_text;
	document.getElementById("oneshow").title = opt_text;
	document.getElementById("onetext").innerHTML=OneDescribe[img_index];
	
	var img_ok=isImageOk(document.getElementById("oneshow"));
	if(!img_ok){
		window.setTimeout(OneReload, reloadTime, img_index, caller_func);
	}else{ 		
		eval(str2FuncName(caller_func, '|')+';');
	}
}
function str2FuncName(str , sep){
	var sepa = typeof(sep) == 'undefined' ? '|' : sep;
	
	var ary = str.split(sepa);
	
	var strFunc = ary.pop();
	var strPrame = '';
	if(ary.length > 0){
		//fucntion name and parameters in string
		var strPrame = ary.join(",");	
	}
	return strFunc+'('+strPrame+')';
}

// Random Effect for change image (only on IE)
function effektberechnen(){
	if (document.all){ /* IE only */
	document.getElementById("oneshow").filters.revealTrans.Transition=Math.floor(Math.random()*23)
	document.getElementById("oneshow").filters.revealTrans.stop()
	document.getElementById("oneshow").filters.revealTrans.apply()
	}
}
function effektzeigen(){
	if (document.all)
	document.getElementById("oneshow").filters.revealTrans.play()
}
// check image load successfully 
function isImageOk(img) {
    // During the onload event, IE correctly identifies any images
    // that weren't downloaded as not complete. Others should too.
    // Gecko-based browsers act like NS4 in that they report this
    // incorrectly: they always return true.
    if (!img.complete) {
		//alert('load image failed');
        return false;
    }
/*
	// However, they do have two very useful properties: naturalWidth
    // and naturalHeight. These give the true size of the image. If
    // it failed to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
		alert('load image failed');
        return false;
    }
*/
	// However, they do have two very useful properties: naturalWidth
    // and naturalHeight. These give the true size of the image. If
    // it failed to load, either of these should be zero.
    if (typeof img.width != "undefined" && img.width == 0) {
		//alert('load image failed');
        return false;
    }
	
    // No other way of checking: assume it's ok.
    return true;
}
//reload image

function adjustImageSize(img_elem,maxWidth,maxHeight){
  var x=parseInt(img_elem.width);
  var y=parseInt(img_elem.height);
  if (x>maxWidth) {
    y*=maxWidth/x;
    x=maxWidth;
  }
  if (y>maxHeight) {
    x*=maxHeight/y;
    y=maxHeight;
  }
  img_elem.width=x;
  img_elem.height=y;
}


/* print mailto link*/
/*
var user;
var domain;
var suffix;
function jemail(user, domain, suffix){
document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + user + '@' + domain + '.' + suffix +"<\/a>");
}
*/
/* print iframe of google map*/
/*
function loadGoogleMap(){
	var iGoogleMap= document.getElementById("iframe_googlemap");
	if(iGoogleMap != null ){
		//var iGoogleMap= document.getElementById("iframe_googlemap");
		iGoogleMap.innerHTML='<iframe width="748" height="600" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=104958179560654985497.00043a8ce8be9934f7f0a&amp;om=0&amp;s=AARTsJqJzSh30FeC53ljUGI9f_UCaJU_-A&amp;ll=7.834951,98.297918&amp;spn=0.006377,0.008025&amp;z=17&amp;output=embed"></iframe>';	
	}
}

function popWin(URL,w,h) {
  if(URL!=""){
    window.open(URL, "Code","resizable=yes,scrollbars=yes,toolbar=no,status=no,height="+h+",width="+w);			
  }
}
*/
