
//----------------------------------------------- Browser Check ----------------------------------------------------------------------

  var agent = navigator.userAgent.toLowerCase();
  var name = navigator.appName.toLowerCase();
	
function browserCHK() {
  

  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);


  this.ns = ((name.indexOf('netscape') == -1) != (agent.indexOf("opera")==-1) || (agent.indexOf("msie")==-1));
  this.ns4 = (this.ns && (this.major==4));
  this.ns6 = (this.ns && (this.major>=6));

  this.java = (navigator.javaEnabled());	
  
}


is = new browserCHK();



// -------------------------------------- find Object -----------------------------------------------------------------------

function findObject(layerName, textString){					// Finds all the object on the html page 

	var p,i,x;

  	if(!textString){ 
  		textString = document;
  	}
  	if((p = layerName.indexOf("?"))> 0 && parent.frames.length){

    		textString = parent.frames[layerName.substring(p+1)].document; layerName = layerName.substring(0,p);
  	}

  	if(!(x = textString[layerName]) && textString.all)			// netscape 4
  	
  		x = textString.all[layerName]; 
  	
  	for (i = 0; !x && i < textString.forms.length; i++) 
  	
  		x = textString.forms[i][layerName];
  		
  	for(i = 0; !x && textString.layers && i < textString.layers.length; i++) 
  	
  		x = findObject(layerName,textString.layers[i].document);
	
  	if(!x && document.getElementById)					// netscape 6, explorer
  	
  		x = document.getElementById(layerName); return x;
	}
	

// ----------------------------------- Set TextToLayer -----------------------------------------------------------------


function setTextToLayer(layerName,x,text) {					// write text to layers
	
	var newText = '' + text + '';

  	if ((obj=findObject(layerName))!=null) with (obj){
	    	if (document.layers){
	    	
	   		document.write(unescape(newText)); document.close();
		}
		
	    	else{ 
	    		innerHTML = unescape(newText);
		}
	}
}


// ----------------------------------- Set Title ----------------------------------------------------------------------

function setTitle(text){									// z-index: 10


	text =  '<span class="title">' + text + '</span>';  				// only for stylesheet

if (is.ns4){

	setTextToLayer('title_layer','',text);
	
}else{

	setTextToLayer('TitleLayer','',text);
	
}	
}



// ----------------------------------- Set Link Text -----------------------------------------------------------------------

function setLinkText(text){									// z-index: 20

	text = '<span class="links">' + text + '</span>';     				// only for stylesheet

if (is.ns4){

	setTextToLayer('link_layer','',text);
	
}else{
	setTextToLayer('LinkLayer','',text);
	
}
}


// ------------------------------------- Set View Title ----------------------------------------------------------------

function setViewTitle(text) {								// z-index: 30

	text = '<span class="viewtitle"><b>' + text + '</b></span>';		// only for stylesheet

if (is.ns4){

	setTextToLayer('view_title_layer','',text);
	
}else{
	setTextToLayer('ViewTitleLayer','',text);
	
}
}


// ------------------------------------- Set View Text ----------------------------------------------------------------

function setViewText(text) {								// z-index: 40

		text = '<span class="viewtext">' + text + '</span>'; 				

if (is.ns4){

	
	setTextToLayer('view_text_layer','',text);
	
}else{
	
	setTextToLayer('ViewTextLayer','',text);
	
}
}


// ------------------------------------- Set Navigation ----------------------------------------------------------------

function setNavigation(text) {								// z-index: 50

		text = '<span class="viewtext">' + text + '</span>'; 				

if (is.ns4){

	
	setTextToLayer('navigation_layer','',text);
	
}else{
	
	setTextToLayer('NavigationLayer','',text);
	
}
}


// ------------------------------------- Set Thumbnails ----------------------------------------------------------------

function setThumbnail(text) {							// z-index: 60


if (is.ns4){

	setTextToLayer('thumbnail_picture_link_layer','',text);
	
}else{
	setTextToLayer('ThumbnailPictureLinkLayer','',text);
	
}
}


// --------------------------------------- Fade To ------------------------------------------------------------------

function fadeTo(text){									// fade to next view
  	document.ImageZoom.fadeToTag(text);
}

// ---------------------------------------- Zoom To ------------------------------------------------------------------

function zoomTo(text){									// zoom to next view
  	document.ImageZoom.zoomToTag(text);
}

// ------------------------------------------ Set Zoom Mode ----------------------------------------------------------


function setZoom(mode){									// set the regulerzoom(0) or postcardzoom(1) method
  	document.ImageZoom.setZoomMode(mode);
}


// ------------------------------------- Set Transition / ArrowStyle ---------------------------------------------------------------


function setArrowStyle(style){								// set the transition to flip(0), fade(1), rotate(2) or slide(3)
  	document.ImageZoom.setArrowStyle(style);
   }



// ------------------------------------- Set ZoomTime ---------------------------------------------------------------

function setZoomTime(time){								// set the zoom or transition time in milliseconds(1000)
  	document.ImageZoom.setZoomTime(time);
   }



// ---------------------------------- Reload Page -----------------------------------------------------


function ReloadPage(init) {
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pageWidth=innerWidth; document.pageHeight=innerHeight; onresize=ReloadPage; }}
  else if (innerWidth!=document.pageWidth || innerHeight!=document.pageHeight) location.reload();
}
ReloadPage(true);


// ---------------------------------------- Set Autozoom ------------------------------------------------------------------

var autoZoom = false; 
var changeTime = 500;
var countTimer = null;
var timerRunning = false;
var tagList = new Array("1", "1", "0", "2", "2", "0", "1", "1", "0", "2", "2", "0"); 


var tagID = 0;


function getPos(num){						// kollar vilken possition appleten är i
	
	if(num!=""){
		tagID=num;
	}
	
}

function setAutozoom(value) {

  if (value == 1){
  
  	autoZoom = true;
  	//alert(autoZoom);
  	
  	rotationTimer = setTimeout("startTimer();", 500);   		// sätter tiden innan rotation startar
  	timerRunning = true;
  }
  else{
  
  	autoZoom = false;
  	//alert(autoZoom);		
 
  	rotationTimer = setTimeout("startTimer();", 500);   		// sätter tiden innan rotation startar
  	timerRunning = true;
}	  
}

toGo = 0;							// kollar hur många possitioner som skal vridas, börjar med noll


function startTimer() {
	

	if (isDone() == 1) {					// om appleten är färdigladdad
	    
	    if (autoZoom == false){
	  
	    getPos(tagID);					// och possitionerna blir nollställda
	    stopTimer(countTimer);
	    stopTimer(rotationTimer);
	    return;
	    }
	        
	    antal = tagList.length;				// kolla arrayns antal possitioner
	    zoomTo(tagList[tagID]);
	    toGo++;
	 
	if (tagID >= antal){					// om tagID är mer än längden av array nolla tagID
	    
	    tagID=0;
	    }
	    
	    tagID++;						
  	
  	
	if (toGo >= antal){					// om hur possitionerna som har tagits är större än längden på arrayn stannar klockorna ( countTimer & rotationTimer )
		
	    if (autoZoom == true){
	    
	    	setAutozoom(1);
	    	toGo = 0;
	    	tagID=0;
	    }
	    		
	    getPos(tagID);					// och possitionerna blir nollställda
	    toGo=0;
	    stopTimer(countTimer);
	    stopTimer(rotationTimer);
	    return;
	    }
	  
	  
	}
	
	    countTimer = setTimeout("startTimer();", 1000);
	    timerRunning = true;
}




function stopTimer() {
  	
  	if(timerRunning){
    		clearTimeout(countTimer);
 		timerRunning = false;
	}
}



function isDone() {
    return document.ImageZoom.isDone();
}

