// JavaScript Document

function buy($isbn){
 //buy from Amazon using 10 or 13 digit ISBNs
	/*if ($country=="US"){
		$tag='wwwjuliadonco-20';
		$url='http://www.amazon.com';
	}
	else{  */
		$tag='lindachapmana-21';
		$url='http://www.amazon.co.uk';
	//}
	//debugger
	$re=/[- ]/g;  //the regular expression to remove hyphens and spaces
	$isbnraw=$isbn.replace($re,"");
			
	$amazonlink="";
	if ($isbnraw.length==10){//traditional
		$amazonlink= $url  + "/exec/obidos/ASIN/" + $isbnraw + "/" + $tag ;
		}
	else  {//13 digit means work out the 10 digit equivalent
		$isbncore=$isbnraw.substr(3,9);
		mult=10;
		totsum=0
		//alert($isbncore);
		for(c=0; c<9; c++){
			totsum += mult * $isbncore.substr(c,1)
			mult--
		}
		rem=totsum%11
		if(rem==0) addon="0";	else addon=String(11-rem)
		
		if(addon=="10"){addon="X"}
		$isbn10=$isbncore + addon
		$amazonlink=$url  + "/exec/obidos/ASIN/" + $isbn10 + "/" + $tag ;
		//alert($amazonlink)
					
	}
	window.location.href=$amazonlink;
	
}


function getpic(pagelink){ //in this, page is the name of the page
switch (pagelink){
	 	case 'home': return "url(i/navbgs/nav21star.gif)";
		case 'news': return "url(i/navbgs/nav21Lightning.gif)";
		case 'abou': return "url(i/navbgs/nav21Linda.gif)";
		case 'unic': return "url(i/navbgs/nav21unicorn.gif)";
		case 'star': return "url(i/navbgs/nav21stardust.gif)";
		case 'love': return "url(i/navbgs/nav21loving.gif)";
		case 'skat': return "url(i/navbgs/nav21skate.gif)";
		case 'nqam': return "url(i/navbgs/nav21mermaid.gif)";
		case 'geni': return "url(i/navbgs/nav21genie.gif)";
		case 'supe': return "url(i/navbgs/nav21powers.gif)"; 
		case 'brig': return "url(i/navbgs/nav21bright.gif)";
		case 'othe': return "url(i/navbgs/nav21other.gif)";  
		case 'funs': return "url(i/navbgs/nav21smiley.gif)"; 
		case 'cont': return "url(i/navbgs/navContact1.gif)"; 
	} 
}


function popup(o){
	linkid=o.id
	pageid=document.getElementsByTagName('body')[0].id
	if(linkid=='l' + pageid) {
		return //no graphic needed
	}
	pagelink=linkid.substr(1)
	//debugger
	path=getpic(pagelink)
	
	t=o.offsetTop - 50
	l=o.offsetLeft + 100
	document.getElementById('navpic').style.left=l+"px"
	document.getElementById('navpic').style.top=t+"px"
	document.getElementById('navpic').style.backgroundImage=path
	//document.getElementById('navpic').style.border="1px solid blue"
}

function popdown(o){
	//path=getpic(pic)
	document.getElementById('navpic').style.backgroundImage='none'
}



function twinkle(){
	//debugger
	nav=document.getElementById("lindatxt")
	pos=nav.style.backgroundPosition
	nr=parseInt(pos)
	nr=nr+30
	pos=nr+"px 50%"
	nav.style.backgroundPosition=pos
	//alert(pos)
	setTimeout("twinkle()",80)
}


function stars(){
	//alert("here")
	h=document.body.offsetHeight
	document.getElementById("starcol").style.height=(h-180)+"px";
	
	maxh=h-100 //leave room for a big star
	//alert(h)
	nrstars=Math.floor(h/70)  //this means a star every 70px
	
	ihtml1="";
	ihtml2="";
	y1last=0
	y2last=0
	for(i=1; i<=nrstars; i++){
		s1=Math.random()
		s2=Math.random()
		scale1=s1*s1 //smaller stars favoured. Most scales will be small but could be large
		scale2=s2*s2
		y1=y1last + Math.floor(Math.random()*100)
		y2=y2last + Math.floor(Math.random()*100)
		if(i==1){y1=0; y2=0}  //y1, y2 is the distance down the screen to the top of this star
		w1=10+Math.floor(scale1*50) //w1 h1, w2 h2 is the height and width of the star
		h1=10+Math.floor(scale1*50)
		w2=10+Math.floor(scale2*50)
		h2=10+Math.floor(scale2*50)
		y1last=y1+h1
		y2last=y2+h2
		x1=Math.floor(Math.random()*(190-w1))
		x2=Math.floor(Math.random()*(190-w2))
		//choose different coloured stars at random.
		
		star1gif=getstar()
		star2gif=getstar()
		
		star1='<img src="' + star1gif + '" style="position:absolute; left:' + x1 +'px; top:' + y1 +'px; width:' + w1 +'px; height:' +h1 +'px ">\n'
		star2='<img src="' + star2gif + '" style="position:absolute; left:' + x2 +'px; top:' + y2 +'px; width:' + w2 +'px; height:' +h2 +'px ">\n'
		ihtml1+=star1
		ihtml2+=star2						
	
	}

	pos1=document.getElementById("stars1")
	pos2=document.getElementById("stars2")
	pos1.innerHTML=ihtml1
	pos2.innerHTML=ihtml2;
}

//function getstar(){
//return "i/star60.gif"
//}


function getstar(){
	 colour=Math.random()*7
	 colour=Math.ceil(colour); 
	//debugger
		switch(colour) {
			
			case 7:
				return "i/starred.gif"
				break		
				
			case 6:
				return "i/stargreen.gif"
				break	
				
			case 5:
				return "i/staryellow.gif"
				break	
				
			case 4:
				return "i/starblue.gif"
				break	 
			
			default:
				return "i/star60.gif"
		}
}