var slidesSet = 'mosselen';
var so;
var variables;
var base;
var gallery;
var selectedGallery;
var flash;

function layoutInit(){
	document.getElementById('searchButton').value= '';
}

function searchFocus(langVar){
	var searchQuery = document.getElementById('searchQuery');
	if(searchQuery.value == langVar){
		searchQuery.value = '';
		searchQuery.className = 'focus';
	}
	
	return false;
}

function searchBlur(langVar){
	var searchQuery = document.getElementById('searchQuery');
	if(searchQuery.value == ''){
		searchQuery.value = langVar;
		searchQuery.className = 'blur';
	}
	
	return false;
}

var onLoad = false;

window.onload = function() {
	layoutInit();
	if(typeof aryImages != 'undefined'){
		if(aryImages.length > 0){
			productImageInit();
		}
		setImagePos();
	}
	onLoad = true;
	setTimeout("flashInit()",1000);
}

window.onscroll = function () {
	if(onLoad && typeof aryImages != 'undefined'){
		setImagePos();
	}
}

function getPageHeight(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
  	}

	return yWithScroll;
}


function setImagePos(){
	var imageLink = document.getElementById('imageLink');
	var imagePos = document.getElementById('imagePos');
	var imageHeight = imageLink.offsetHeight;
	var bottomMargin = 70;
	var header = 184;
	
	if(getScrollY() > (getPageHeight()-imageHeight-bottomMargin)){
		imageLink.style.top = (getPageHeight()-imageHeight-bottomMargin-header)+'px';
	} else {	    
		if(imagePos.offsetTop<(getScrollY()-header) ){
			imageLink.style.top = (getScrollY()-(header-10))+'px';
		} else {
			imageLink.style.top = (imagePos.offsetTop+20)+'px';
		}
	}
}

nextGallery = 0;

function loadGallery(gallery){
	nextGallery = gallery;
	timer = 0;
}

var timer = 100;

function flashTimer(){
	setTimeout("flashTimer()",100);
	timer++;
	
	if(timer > 5 && timer < 10){
		loadFile({file:'/playlist.php?id='+nextGallery});
		timer = 100;
	}
}

function flashInit(){
	var so = new SWFObject('/'+base+"/jwImage/imagerotator.swf","flashGallery","260","198","8");
	so.addParam("allowscriptaccess","always");

	so.addVariable("file","/playlist.php?id="+selectedGallery);
	so.addVariable("shownavigation","false");
	so.addVariable('transition','fade');
	so.addVariable("shuffle","true");
	so.addVariable("linktarget","_self");

	so.addVariable("enablejs","true");
	so.addVariable("javascriptid","flashGallery");

	so.addVariable("width","260");
	so.addVariable("height","198");

	so.write("slideLoader");
	
	flashTimer();
}

function loadFile(obj) { thisMovie("flashGallery").loadFile(obj); };

function addItem(obj,idx) { thisMovie("flashGallery").addItem(obj,idx); };

function removeItem(idx) { thisMovie("flashGallery").removeItem(idx); };

function getLength(swf) { return(thisMovie(swf).getLength()); };


// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};


function setGallery(param){
	if(param == 0) return;
	loadFile('playlist.php?id='+param);
}

function groupHover(galleryId){
	if(galleryId > 8) galleryId = 0;
	document.getElementById('technav').style.display='none';
	document.getElementById('groupsnav').style.display='';
	document.getElementById('groupslink').className='active';
	document.getElementById('techlink').className='';
	
	flash.setGallery(galleryId);
}

function techniqueHover(galleryId){
	if(galleryId <= 8) galleryId = 8;
	document.getElementById('groupsnav').style.display='none';
	document.getElementById('technav').style.display='';
	document.getElementById('techlink').className='active';
	document.getElementById('groupslink').className='';
	
	flash.setGallery(galleryId);
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function productImage(imgIndex,alt,visible, href){
	var imageLoader = document.getElementById('imageLoader');
	var imageLink = document.getElementById('imageLink');

	imageLoader.src = aryImages[imgIndex];
	imageLoader.alt = alt;
	imageLink.href = href;
	if(!visible) imageLink.style.display = 'none';
	else imageLink.style.display = 'block';
}

function productImageInit(){
	for (i=0; i < aryImages.length; i++) {
		var preload = new Image();
		preload.src = aryImages[i];
	}
}
