// JavaScript Document
function switch1(div) {
var option=['one','two','three'];
for(var i=0; i<option.length; i++) {
  if (document.getElementById(option[i])) {
  obj=document.getElementById(option[i]);
  obj.style.display=(option[i]==div)? "block" : "none";
}
}
}
//

// switch content (unobtrusive)
function hidestories() {
var divs=document.getElementById('stories').getElementsByTagName('div');
for (j=0; j<divs.length; j++) {
    var rE = new RegExp("(^|\\s)" + 'story' + "(\\s|$)");
	if (rE.test(divs[j].className)) {
		divs[j].style.display="none";
		}
	}
}
function hidetstories() {
var divs=document.getElementById('tstories').getElementsByTagName('div');
for (j=0; j<divs.length; j++) {
    var rE = new RegExp("(^|\\s)" + 'story' + "(\\s|$)");
	if (rE.test(divs[j].className)) {
		divs[j].style.display="none";
		}
	}
}
function stories(first) {
var thebuttons=document.getElementById('thebuttons').getElementsByTagName('a');
for (i=0; i<thebuttons.length; i++) {
	thebuttons[i].onclick=function() {
		hidestories();
		var thestory=(this.href).split("#",2)[1];
		document.getElementById(thestory).style.display="block";
		return false;
		}
	}
	if (first) {
		var firstone=document.getElementById('stories').firstChild;
		if (firstone.nodeType != 1) {firstone = firstone.nextSibling;}
		firstone.style.display="block";
	}
}


function anon(el) {
	hidetstories();
	var thestory=(el.href).split("#",2)[1];
	document.getElementById(thestory).style.display="block";
	return false;
}		
function tstories(first) {
var thebuttons=document.getElementById('thebuttons').getElementsByTagName('a');
for (i=0; i<thebuttons.length; i++) {
	thebuttons[i].onclick=function() {anon(this)}
	}
	var els=document.getElementsByTagName('a');
	var rE = new RegExp("(^|\\s)" + 'link' + "(\\s|$)");
	for (j=0; j<els.length; j++) {
	if (rE.test(els[j].className)) {
		els[j].onclick=function () {anon(this);}
		}
	}
	if (first) {
		var firstone=document.getElementById('tstories').firstChild;
		if (firstone.nodeType != 1) {firstone = firstone.nextSibling;}
		firstone.style.display="block";
	}
}

//

// switch content4 - for the 'current' style
function hidestories2() {
var divs=document.getElementById('stories2').getElementsByTagName('div');
for (j=0; j<divs.length; j++) {
    var rE = new RegExp("(^|\\s)" + 'story' + "(\\s|$)");
	if (rE.test(divs[j].className)) {
		divs[j].style.display="none";
		}
	var thebuttons=document.getElementById('thebuttons').getElementsByTagName('a');
	for (k=0; k<thebuttons.length; k++) { // loop throught the buttons and remove the 'current' class
		var li=thebuttons[k].parentNode;
		li.className=li.className.replace(new RegExp("current"+"\\b"), "");
		}
	}
}

function stories2(first) {
var thebuttons=document.getElementById('thebuttons').getElementsByTagName('a');
for (i=0; i<thebuttons.length; i++) {
	thebuttons[i].onclick=function() {
		hidestories2();
		var thestory=(this.href).split("#",2)[1];
		document.getElementById(thestory).style.display="block";
		this.parentNode.className+=" current";  // set the 'current' class to the clicked button
		return false;
		}
	}
	if (first) {
		var firstone=document.getElementById('stories2').firstChild;
		if (firstone.nodeType != 1) {firstone = firstone.nextSibling;}
		firstone.style.display="block";
		var firstbutton=document.getElementById('thebuttons').firstChild;
		if (firstbutton.nodeType != 1) {firstbutton = firstbutton.nextSibling;}
		firstbutton.className+=" current"; // set the 'current' class to the first button
	}
}
//

function switchlang(lang)
{
if (document.getElementById('switchlang')) {
var option=['english','french','spanish','japanese'];
for(var i=0; i<option.length; i++) {
	for(var j=1; j<5; j++) {
	obj=document.getElementById(option[i]+j);
    obj.style.display=(option[i]==lang)? "block" : "none";    }
	}
var option=['eng','fre','spa','jap']; //to show the 'active' language
for(var i=0; i<option.length; i++) {
	obj=document.getElementById(option[i]);
    obj.style.color=(option[i]==lang.substr(0,3))? "red" : "navy";    }	
}
}
//
function switch2() 
{
var option=['tel1','tel2'];
for(var i=0; i<option.length; i++) 
{	obj=document.getElementById(option[i]);
    obj.className=(obj.className=="visible")? "hidden" : "visible";    }
}
//

//
function toggle(div) 
{
var option=['wine1','beer1','whisky1'];

for(var i=0; i<option.length; i++) 
{	obj=document.getElementById(option[i]);
    obj.style.display=(option[i]==div) && !(obj.style.display=="block")? "block" : "none"; }
}

//
function pmtoggle(div) {
var option=['wine1','beer1','whisky1'];
var c=0;
	for(var i=0; i<option.length; i++) {	
	var obj=document.getElementById(option[i]);
	obj.style.display=(option[i]==div) && !(obj.style.display=="block")? "block" : "none"; 
	if (obj.style.display=="none"){c++;}
	if (c==3){document.images['plusminus'].src="plus.gif";}
	else {document.images['plusminus'].src="minus.gif";}
	}
}

//

function switchImg(i){
document.images["wine"].src = i;
}
//

function ads(div) {
obj=document.getElementById(div);
if (obj) {
	obj.style.display=(obj.style.display=="none")? "block" : "none"; 
	}
}

function tcform(div) {
obj=document.getElementById(div);
obj.style.display=!(obj.style.display=="block")? "block" : "none";  
document.location.href="#end";
}

function bg() {
w=document.body.offsetWidth;
if (w<700){
	document.getElementById('body').style.background="white";
}
else{
	document.getElementById('body').style.background="transparent";
}
}
//
function tol () {
tl=document.getElementById('toplinks');
w=document.body.offsetWidth;
if (tl && w<700) {
	tl.style.display="none";
}
if (tl && w>700) {
	tl.style.display="block";
}
}
//

function fixH(one,two) {
if (document.getElementById(one)) {
	var lh=document.getElementById(one).offsetHeight;
	var rh=document.getElementById(two).offsetHeight;
	var nh = Math.max(lh, rh);  
	document.getElementById(one).style.height=nh+"px";
	document.getElementById(two).style.height=nh+"px";
	}
}

//this does it for three
function sortNum(a,b) { return b-a} 
function fixH2(one,two,three) {
	if (document.getElementById(one)) {
		var obj=new Array(3);
		var option=[one,two,three];
		for(var i=0; i<option.length; i++) {
			document.getElementById(option[i]).style.height="auto";
			obj[i]=document.getElementById(option[i]).offsetHeight;
			nh=obj.sort(sortNum);
			}		
	 	nh1=nh.splice(1,2);
		for(var i=0; i<option.length; i++) {
			document.getElementById(option[i]).style.height=nh+"px";
			}
	}
}
//
////for the highlight page
function show(l){
var name=l.href;
var nam=name.substr(37,10);
var divs=document.getElementsByTagName('div');
for (var x=0;x<divs.length;x++)
{
divs[x].style.color="black";
}
var obj=document.getElementById(nam);
obj.style.color = "red" ;

}
function hili() {
if(document.getElementById('toplinks')) {
	document.getElementById('one').style.display="block";
	document.getElementById('two').style.display="block";
	document.getElementById('three').style.display="block";
var mn=document.getElementById('toplinks');
var as=mn.getElementsByTagName('a');
for (var i=0;i<as.length;i++) {
as[i].onclick=function(){show(this)};
}		
}
}

/* 
styTog() -- a function to toggle CSS style attributes
This function accepts four parameters from the calling event:
targ_id, which is the id of the target element;
sty_attrJ, which is the style attribute's name in JavaScript syntax;
sty_attrC, which is the style attribute's name in CSS syntax;
set_val, which is the second toggle state value;
    
The element id, "zedSpan" is reserved for this function's use.
*/
function styTog(targ_id,sty_attrJ,sty_attrC,set_val){  
var targ=document.getElementById(targ_id);
var targ_stat="";
var targ_sty="";
var attr_chk=sty_attrC.toLowerCase()
var excp_flag=0;
 if(attr_chk.indexOf("color")!=-1 || attr_chk.indexOf("font")!=-1){
    	excp_flag=1;
    if(!document.getElementById("zedSpan")){
    	var insSpan=document.createElement("span");
    	insSpan.setAttribute("id","zedSpan");
    	document.body.appendChild(insSpan);
    	}
    var zS=document.getElementById("zedSpan").style
    zS[sty_attrJ]=set_val;
    }
    if(targ.currentStyle){  //code for IE
    if(excp_flag==1)set_val=zS[sty_attrJ];
    	targ_stat=targ.currentStyle[sty_attrJ];
    }else{  //code for W3C-spec-compatible
    if(excp_flag==1){
    var tst_span=document.getElementById("zedSpan");
    var tst_sty=document.defaultView.getComputedStyle(tst_span,"");
    	set_val=tst_sty.getPropertyValue(sty_attrC);
    	excp_flag=0;
    	}
targ_sty=document.defaultView.getComputedStyle(targ,"");
targ_stat=targ_sty.getPropertyValue(sty_attrC);
    }
targ_stat!=set_val ? targ.style[sty_attrJ]=set_val : targ.style[sty_attrJ]="";
}

//suckerfish//

	
sfHover = function() {
	var sfEls = document.body.getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//

function twoWindows (one,two) {
window.open(one);
window.open(two);
}

/////////////////
function randImg() {
var links= new Array(3);
links[0]='wine.jpg';
links[1]='whisky.jpg';
links[2]='beer.jpg';
var ran_unrounded=Math.random()*2;
var rand=Math.round(ran_unrounded);
var image= links[rand];
var imagehtml='<img src="../Services/js/'+image+'" alt="'+image.replace(/.jpg/, "")+'" />';
p = document.getElementById('rand-img');
if (p) {
	range = document.createRange();
	range.setStartBefore(p);
	p.appendChild(range.createContextualFragment(imagehtml));
	}
}
///

function randImgLink() {
var links= new Array(3);
links[0]=new Array();
links[0]['img']='wine.jpg';
links[0]['link']='http://wine.com';
links[1]=new Array();
links[1]['img']='whisky.jpg';
links[1]['link']='http://whisky.com';
links[2]=new Array();
links[2]['img']='beer.jpg';
links[2]['link']='http://beer.com';
var ran_unrounded=Math.random()*2;
var rand=Math.round(ran_unrounded);
var link= links[rand];
var linkhtml='<a href="../Services/js/'+link['link']+'"><img src="../Services/js/'+link['img']+'" alt="'+link['img'].replace(/.jpg/, "")+'" /></a>';
p = document.getElementById('rand-img-link');
if (p) {
 range = document.createRange();
 range.setStartBefore(p);
 p.appendChild(range.createContextualFragment(linkhtml));
 }
}
window.onload=randImgLink;
///









function toggleNextByIdAndTag6(el,tname) {
	var ccn="clicker";
	clickers=document.getElementById(el).getElementsByTagName(tname);
	for (i=0; i<clickers.length; i++) {
		clickers[i].className+=" "+ccn;
		clickers[i].onclick=function() {toggleNext6(this,tname)}
		toggleNext6(clickers[i],tname,1);
	}
}


// remove background on guide 
function no_bg() {
	if (document.getElementById('guide')) {
	document.getElementById('no_bg').onclick=function() {
		document.body.style.backgroundImage="url()";
		}
	}
}






window.onload=function()
{
	switch1('one');
	switchlang('english');
	ads('commentform');
	bg ();
	tol();
	fixH('leftcolumn','rightcolumn');
	fixH2('left','right','centre');
	hili();
	randImg();
	randImgLink();
	no_bg();
	if (document.getElementById('css_sub')) {
	toggleNextByTagAndClassNameSpesh('a','sub');
	}
	if (document.getElementById('stories')) {
	hidestories();
	stories(1);
	}
	if (document.getElementById('tstories')) {
	hidetstories();
	tstories(1);
	}
	if (document.getElementById('stories2')) {
	hidestories2();
	stories2(1);
	}
	
}
window.onresize=function()
{
	bg();
	tol();
}
