//Checking for and stopping the script if error.
var error=0
var vars
window.onerror=ops;
function ops(){
	error=1
	return true
}
//Browsercheck
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom && parseInt(this.ver)>=4)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	this.ie4mac=this.ie4 && navigator.userAgent.indexOf("Mac")>-1
	if(this.ie4mac) ops()
	return this
}
bw=new checkBrowser()

/*********************************************************
When you use the control panel 
The variables you enter in there is picked up here.
These lines can be deleted if you don't want the option of 
Editing the script 
*********************************************************/
vars=location.search
vars=vars.substr(1,vars.length)
if(vars){
	vars=vars.split("|")
	num_flakes640=parseInt(vars[0])
	num_flakes800=parseInt(vars[1])
	num_flakes1024=parseInt(vars[2])
	num_flakes1200=parseInt(vars[3])
	flake_image_set=parseInt(vars[4])
	flake_wind=parseInt(vars[5])
	flake_swing=parseInt(vars[6])
	flake_down=parseInt(vars[7])
	flake_offset_rotateby = parseFloat(vars[8])
	flake_move_timeout = parseInt(vars[9])
	flake_copyright_place=parseInt(vars[10])
}
// *********************************************************

//Here are the default variables.
//Set these to configure the script.
if(!vars){
	num_flakes640=8; //Number of flakes on resolution 640x480
	num_flakes800=12; //Number of flakes on resolution 800x600
	num_flakes1024=16; //Number of flakes on resolution 1024x768
	num_flakes1200=20 //Number of flakes on higher resolutions
	flake_image_set=1; //What set of images, set one means: flake1_1.gif and so on, set 2 is flake2_1.gif...
	flake_wind=0 //Wind on the flakes
	flake_swing=3; //How much should it swing
	flake_down=2; //How much should it go down
	flake_offset_rotateby = 0.15; //Rotation
	flake_move_timeout = 100; //How fast should the time go
	flake_copyright_place=3 //Where do you want the copyright layer to be placed, corners 1,2,3 or 4
}
num_flake_images = 5; //How many different images do you have? 
flake_edit_show=0 //Show edit link? 0 or 1
flake_copyright_target="_blank" //The target of the copyright link. Set to "" for same window.


//****** If regular links 
flake_links=0 //Do you want the flakes to link somewhere? (if image_swap set this to 0)
flake_target="" //Target window for flake links
//Place your links in the array below. (set 0 for no link)
flake_urls=new Array('http://www.6myk.com', 'http://www.6myk.com', 'http://www.6myk.com')

//******* If imageswap onclick

//IF FLAKE_LINKS=1 then it will go the link the second time it is clicked!
flake_swap_images=0 //if regular links set this 0
//preloading swap_images
if(flake_swap_images){
	flake_swap_images=new Array()
	for(i=0;i<num_flake_images;i++){
		flake_swap_images[i]=new Image();
		flake_swap_images[i].src="flake_swap"+flake_image_set+"_"+(i+1)+".gif";
	}
}

//Preloading images
flake_pre=new Array();
for(i=0;i<=num_flake_images;i++){
	flake_pre[i]=new Image();
	flake_pre[i].src="flake"+flake_image_set+"_"+(i+1)+".gif";
}

//Swapping images
function flake_swap(num,imgnum){
	if(flake[num].swapped && flake_links && flake_urls[num]) location.href=flake_urls[num]
	else{
		flake[num].swapped=true
		flake[num].ref.images["imgFlake"+num].src=flake_swap_images[imgnum].src	
	}
}


//Placing copyright (happens onload and onscroll)
function place_copyright(){
	if(flake_copyright_place==1) flake_copyright.moveIt(5, 5+eval(scrolled))
	else if(flake_copyright_place==2) flake_copyright.moveIt(pageWidth-100, 5+eval(scrolled))
	else if(flake_copyright_place==3) flake_copyright.moveIt(pageWidth-100,pageHeight-flake_copyright.height+eval(scrolled))
	else if(flake_copyright_place==4)flake_copyright.moveIt(5,pageHeight-flake_copyright.height+eval(scrolled))
	flake_edit.moveIt(5,pageHeight-20+eval(scrolled))
//	if(flake_edit_show) flake_edit.css.visibility='visible'
	if(flake_edit_show) flake_edit.css.visibility='hidden'
//	flake_copyright.css.visibility='visible'
	flake_copyright.css.visibility='hidden'
}
//This function get's executed when the user scrolls the page
//in explorer, and every 50 millisecond in netscape (netscape
//doesn't support the onscroll event)
function on_scroll(){
	place_copyright()
	if(bw.ns4) setTimeout("on_scroll()",50)
}
//Placing flakes
function starting_positions() {
	for (i=0; i<flake.length; i++) {
		//This places all the flakes at random positions
		flake[i].offset = Math.random()*5
		flake[i].moveIt(Math.random()*pageWidth- 50,((Math.random()*pageHeight)-50)+eval(scrolled))
		flake[i].css.visibility = "visible"
	}
}
//Moving flakes
function move_flakes() {
	for (i=0; i<flake.length; i++) {
		flake[i].moveIt(flake[i].x+(Math.sin(flake[i].offset) * flake_swing)+flake_wind,flake[i].y+flake_down)
		if((flake[i].y>eval(scrolled)+(pageHeight-flake[i].height-15)) || (flake[i].x>pageWidth-flake[i].width-10 || flake[i].x<0)){ 
		//If the flake is near the ned of the screen, give it a new location.
			flake[i].offset = Math.random() * 5
			flake[i].moveIt(flake[i].css.left = Math.random() *pageWidth-30,-20+eval(scrolled))
		}
		flake[i].offset += flake_offset_rotateby;
		if(flake[i].offset >= 500) flake[i].offset -= 500
	}
	flake_tim=window.setTimeout("move_flakes()", flake_move_timeout)
}
//Controlling script
function control_script(){
	if(flake[0].css.visibility=="visible" || flake[0].css.visibility=="show"){ //Stop
		clearTimeout(flake_tim)
		for(i=0;i<flake.length;i++){flake[i].css.visibility='hidden'}
	}else{
		starting_positions()
		move_flakes()
	}
}
//Initiating the page
//var noimages=true;
var noimages=false;
function flake_init(num){
	if(bw.bw){
		if(!noimages && !error){
			pageWidth=(bw.ns4 || bw.ns5)?innerWidth:document.body.offsetWidth-10;
			pageHeight=(bw.ns4 || bw.ns5)?innerHeight:document.body.offsetHeight-10;
			num_snowflakes=pageWidth<640?num_flakes640:pageWidth<800?num_flakes800:pageWidth<1024?num_flakes1024:num_flakes1200;
			scrolled=bw.ns4?"window.pageYOffset":bw.ns5?0:"document.body.scrollTop";
			if(bw.ie4 || bw.ie5) onscroll=on_scroll 
			starting_positions()
			on_scroll();
			move_flakes()
			window.onresize=resized;
		}else if(!num){
			setTimeout("flake_init(1)",300)
		}
	}
}
//This reloads the page if the page have been resized
function resized(){
	pageWidth2=(bw.ns4 || bw.ns5)?innerWidth:document.body.offsetWidth;
	pageHeight2=(bw.ns4 || bw.ns5)?innerHeight:document.body.offsetHeight;
	if(pageWidth!=pageWidth2 || pageHeight!=pageHeight2){
		location.reload()
	}
}
//Making cross-browser objects
function makeObject(obj){
	this.el=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;	
	this.css=bw.ns4?this.el:this.el.style;	this.moveIt=o_moveIt; 
	this.ref=bw.ns4?this.el.document:document;
	this.height=bw.ns4?this.css.document.height:this.el.offsetHeight;
	this.width=bw.ns4?this.css.document.width:this.el.offsetWidth;
	this.height=this.height?this.height:40;	this.width=this.width?this.width:40;
	return this
}
function o_moveIt(x,y){this.x=x; this.y=y;this.css.left=this.x; this.css.top=this.y}

//Writing out all the layers and styles
if(bw.bw && !error){
	document.write('<style>DIV.clFlake{position:absolute; width:20; height:20; visibility:hidden}#divCopyright{z-index:101; position:absolute; visibility:hidden; '
	+'color:#CCCCCC; font-size:12px; font-family:arial; width:100; height:10}#divEdit{z-index:100; position:absolute; width:100; height:10; visibility:hidden}</style>')
	pageWidth=(bw.ns4 || bw.ns5)?innerWidth:document.body.offsetWidth-10;
	num_flakes=pageWidth<640?num_flakes640:pageWidth<800?num_flakes800:pageWidth<1024?num_flakes1024:num_flakes1200;
	flake=new Array()
	for (i=0; i<num_flakes; i++) {
			flake_num = i%num_flake_images
			if(flake_links && flake_urls[flake_num] && !flake_swap_images){starthref="<a href="+flake_urls[flake_num]+" target="+flake_target+">"; endhref="</a>"}
			else if(flake_links && flake_urls[flake_num] && flake_swap_images){starthref="<a href='#' onclick='flake_swap("+i+","+flake_num+"); return false' target="+flake_target+">"; endhref="</a>"}
			else if(flake_swap_images){starthref="<a href='#' onclick='flake_swap("+i+","+flake_num+"); return false'>"; endhref="</a>"}
			else{starthref=""; endhref=""}
			document.write('<div id="divFlake'+i+'" class="clFlake">'+starthref+'<IMG border="0" name="imgFlake'+i+'" SRC="'+flake_pre[flake_num].src+'">'+endhref+'</div>')
			flake[i]=new makeObject('divFlake'+i)
	}
	document.write('<div id="divCopyright"><a href="#" onclick="control_script(); return false">Start/Stop script</a><br><br>')
	document.write('<a href="http://www.6myk.com" target="'+flake_copyright_target+'">6MYK &copy; 1999 <img onload="noimages=false" src="6myk.gif" width=20 height=20 alt="" border=0 align="middle"></a></div>'
	+'<div id="divEdit"><a href="#" onclick="prop=window.open(\'control.html\',\'properties\',\'width=440px,height=300px,toolbar=0\'); return false">Edit properties</a></div>')
	flake_copyright=new makeObject('divCopyright')
	flake_edit=new makeObject('divEdit')
}
