// JavaScript Document
// JavaScript Document
var navi 		= navigator.appVersion;
var browserIE 	= false;
var browserIE6 	= false;
var browserSAF 	= false;
var scrollSpeed = 50;
var scrollHeight= 10;

if(navi.indexOf("MSIE")>-1){
	browserIE = true;
	var navAr = navi.split(";");
	browserIE6 = (parseFloat(navAr[1].split(" ")[2])<=6.0?true:false);
} else if(navi.indexOf("Safari")>-1){
	browserSAF = true;
}

var width_Avail 		= screen.availWidth;
var heigth_Avail 		= screen.availHeight;
var width_container 	= screen.availWidth * 0.92;
var upper_left			= Math.round((width_Avail-width_container)/2);

window.moveTo(0,0);
window.resizeTo(width_Avail,heigth_Avail);

var innerWidth 		= 0;
var innerHeight 	= 0;

if(!browserSAF){
	innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
	innerHeight	= parseInt((document.documentElement.clientHeight * 1));
}else{
	innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
	innerHeight	= parseInt((document.documentElement.clientHeight * 1));
}

var loadedobjects = "";
var http_request = false;
var rootdomain = "http://"+window.location.hostname

var status 			= 0;
var previous_width 	= 390;
var previous_height = 290;
//alert(rootdomain);
var activeImage		= 0;
var newImage		= 0;
/*
if(browserIE){
	innerWidth = innerWidth-17;
}
*/
var middleX				= innerWidth / 2;
var middleY				= innerHeight / 2;

var fx_mouse_overs 		= new Array;
var fx_listing	 		= new Array;
var active 				= 1;
var activeList			= 0;
var allowClick			= false;
var listing;
var menulist;
var sub_menulist;

var so = new SWFObject("intro.swf", "background", 550, 100, "9", "86A098");
so.addParam("play", "true"); 
so.addParam("scale", "noscale"); 
so.addParam("salign", "tl"); 
so.addParam("allowscriptaccess", "always"); 
so.addParam("allownetworking", "all");
so.addParam("allowfullscreen", "true"); 
so.addParam("wmode", "transparent"); 
so.useExpressInstall('expressinstall.swf');

function setContainer(){
	
	if(FlashDetect.majorAtLeast(9)){

	}else{
		$('div_container').innerHTML = "<br><br><br>You need at least flashplayer 9 to see the full website.<br><br>Click <a href='http://www.adobe.com/products/flashplayer/' target='_blank'>here</a> to download flashplayer from Adobes website.";
	}
	
	document.getElementById('div_container').style.zIndex = 0;
	
	$('div_menu').setStyle('top',(innerHeight-164)/2+'px');
	
	
	var sub_menulist 	= $$('.listing_row');
	sub_menulist.each(function(element) {
		//element.setStyle('width',(innerWidth-670)/2+'px');								
	});
	
	$('div_container').setStyle('top',(innerHeight-180)/2+'px');
	$('div_container').setStyle('left',(innerWidth-300)/2+'px');
	$('div_credits').setStyle('top',(innerHeight-22)+'px');
	$('div_credits').setStyle('left',(innerWidth-130)+'px');
	
	var menuBgList 	= $$('.menu_bg');
	menuBgList.each(function(element) {
		element.setStyle('opacity',0.9);								
	});
	
	$('div_menu_1').addClass('active');
	$('div_about').fade('hide');
	$('div_contact').fade('hide');
	$('div_collection').fade('hide');
	$('div_credits').fade('hide');
	
	var teller 		= 0
	menulist 		= $$('#div_menu .menu');
	menulist.each(function(element) {
		var current = parseInt(element.getProperty('name'));
		teller++;
		fx_mouse_overs[teller] = MorpheItems('div_menu_bg_'+current, 800, Fx.Transitions.Cubic.easeOut);
		
		//ChangeAnim('left', element, 0, 1500/teller, Fx.Transitions.Cubic.easeOut)
		
		element.addEvent('mouseenter', function(){
			var current = parseInt(element.getProperty('name'));
			if(active!=current){
				fx_mouse_overs[current].cancel();
				$('div_menu_bg_'+current).fade(0.5);
				fx_mouse_overs[current].start({'background-color': '#cccccc'});
				element.setStyle('color','#eb2d2e');
			}
		});
			 
		element.addEvent('mouseleave', function(){
			var current = parseInt(element.getProperty('name'));
			if(active!=current){
				$('div_menu_bg_'+current).fade(0.9);
				fx_mouse_overs[current].cancel();
				fx_mouse_overs[current].start({'background-color': '#eb2d2e'});
				element.setStyle('color','#ffffff');
			}
		});
		
		element.addEvent('click', function(){
			if(allowClick){
				var current = parseInt(element.getProperty('name'));
					
				if(active == 3 && current == active){
					enableLists();
				}else{
					$('div_menu_bg_'+current).fade(1);
					$('div_menu_'+active).removeClass('active');
					$('div_menu_'+active).setStyle('color','#ffffff');
					fx_mouse_overs[active].cancel();
					fx_mouse_overs[active].start({'background-color': '#eb2d2e'});
					disablePage(active);
					active		= current;
					activatePage(current);
					element.addClass('active');
					element.setStyle('color','#dddddd');
					fx_mouse_overs[current].cancel();
					fx_mouse_overs[current].start({'background-color': '#888888'});
					if(active == 3 && activeList!=0){
						enableLists();
					}
				}
			}
		});		
		
		
	});
	
	$('div_menu_'+active).setStyle('color','#dddddd');
	fx_mouse_overs[active].cancel();
	fx_mouse_overs[active].start({'background-color': '#888888'});
											
	$('div_container').setStyle('display','block');
	//$('div_container_header').fade(0.6);
	$('div_container_bg').fade(0.8);
	
	var myMorpher_div_container = MorpheItems($('div_container'), 1000, Fx.Transitions.Cubic.easeOut);
	myMorpher_div_container.start({'width': 670, 'height': 120, 'left': (innerWidth-670)/2});
	var myMorpher_div_container = MorpheItems($('div_container_header'), 1000, Fx.Transitions.Cubic.easeOut);
	myMorpher_div_container.start({'width': 650});
	
	
	var TipsImages 	= new Tips($$('.listing_row'),{ fixed: false, showDelay: 0, hideDelay: 0, className: 'tip' });
	
	var listing		= $$('.listing_row');
	listing.each(function(element) {
		var current = parseInt(element.getProperty('id').substring(4));
		fx_listing[current] = MorpheItems(element, 400, Fx.Transitions.Cubic.easeOut);
		
		element.addEvent('mouseenter', function(){
			var current = parseInt(element.getProperty('id').substring(4));
			if(current!=activeList && animating_listing == false){
				fx_listing[current].set({'border-color': '#eb2d2e'});
			}
		});	
		element.addEvent('mouseleave', function(){
			var current = parseInt(element.getProperty('id').substring(4));
			if(current!=activeList && animating_listing == false){
				fx_listing[current].set({'border-color': '#cccccc'});
			}
		});	
		element.addEvent('click', function(){
			if(animating_listing == false){
				animating_listing	= true;
				if(activeList!=0){
					fx_listing[activeList].set({'border-color': '#cccccc'});
				}
				var current 		= parseInt(element.getProperty('id').substring(4));
				activeList 			= current;
				disableLists(current);
				var item_value		= $('item_'+current).value;
				loadNshow('detail.php?categories=1&item='+item_value, 'collection', 'get');
				$('select_collection').setStyle('display', 'none');
			}
		});		  
	});
	
	var fxBG = new Fx.Morph($('div_container_content'), {duration: 1000, transition: Fx.Transitions.Cubic.easeOut,onComplete: function() {
		$('div_container_content').removeClass('loading');
		so.write("div_container_header");
	}});
	fxBG.start({
		'width': 650
	});
	
}

var animating_listing = false;

function openCollection(){
	if(allowClick){
		var current = 3;
			
		if(active == 3 && current == active){
			enableLists();
		}else{
			$('div_menu_'+active).removeClass('active');
			$('div_menu_'+active).setStyle('color','#ffffff');
			disablePage(active);
			active		= current;
			activatePage(current);
			element.addClass('active');
			element.setStyle('color','#000000');
			if(active == 3 && activeList!=0){
				enableLists();
			}
		}
	}
}

function disableLists(not){
	for(i=1;i<=fx_listing.length;i++){
		if(i!=not && fx_listing[i]){
			fx_listing[i].cancel();
			fx_listing[i].start({'height': 0, 'opacity':0});
		}
	}
}
function enableLists(not){
	for(i=1;i<=fx_listing.length;i++){
		if(fx_listing[i]){
			fx_listing[i].cancel();
			fx_listing[i].start({'height': 20, 'opacity':1, 'border-color': '#cccccc'});
		}
	}
	$('collection').fade(0);
	animating_listing 	= false;
	activeList			= 0;
	info_page 			= 1;
	
	$('select_collection').setStyle('display', 'block');
}

//1 = tekst 2 = gallery
info_page = 1;

function toggleInfo(page,folder,url){
	if(page!=info_page){
		info_page = page;
		switch(page){
			case 1:
				$('collection_text').fade(1);
				$('collection_gallery').fade(0);
			break
			case 2:
				$('div_imageBG').fade(0.5);
				$('collection_gallery').fade('hide');
				$('collection_gallery').setStyle('display','block');
				$('collection_text').fade(0);
				$('collection_gallery').fade(1);
				if(url!=''){
					setBigImage(folder,url);
				}
			break;
		}
	}
}


function enterSite(){
	allowClick = false;
	var myMorpher_div_container = MorpheItems($('div_container'), 500, Fx.Transitions.Cubic.easeOut);
	myMorpher_div_container.start({'height': 600, 'left': (innerWidth-670)/2, 'top':(innerHeight-600)/2});
	var myMorpher_div_container_content = MorpheItems($('div_container_content'), 500, Fx.Transitions.Cubic.easeOut);
	myMorpher_div_container_content.start({'height': 580});
	
	$('div_credits').setStyle('display','block');
	$('div_credits').fade('in');
	
	$('div_about').setStyle('display','block');
	$('div_about').fade(1);
	var teller = 0;
	menulist.each(function(element) {
		teller++;
		ChangeAnim('left', element, 0, 1500/teller, Fx.Transitions.Cubic.easeOut)
	});
	allowClick = true;
}

function MorpheItems(target, speed, trans){
	if(target){
		return new Fx.Morph(target, {duration: speed, transition: trans});
	}
}

function ChangeAnim(prop, target, to, speed, trans){
	if(target){
		var myFx = new Fx.Tween(target,{duration:speed, transition: trans});
		myFx.start(prop, to );
	}
}

var myScroller;

function loadNshow(url, target, method){
	var preloader = $(target).empty().addClass('loading');
	var req = new Request({url: url,
	    method: method,
	   	onSuccess: function(responseText) {
			preloader.removeClass('loading');
			var output 	= req.response.text;
			$(target).innerHTML = output;
			switch(target){
				case "div_content":
					soGallery.write('gallery_container');
				break;
				case "collection":
					$('collection').fade('hide');
					$(target).innerHTML = output;
					$('collection').fade(1);
					info_page	= 1;
					var TipsThumbs 	= new Tips($$('.the_thumb'),{ fixed: false, showDelay: 0, hideDelay: 0, className: 'tip_wide' });
	
				break;
			}
		},
		onFailure: function() {
			$(target).set('innerHTML', 'The request failed.');
		}
	});
	req.send();
}

var pageType	 		= 99;


div_arrays = Array('','div_about','div_contact','div_collection');

function disablePage(current){
	$(div_arrays[current]).setStyle('display','none');
	$(div_arrays[current]).fade(0);
}
function activatePage(current){
	$(div_arrays[current]).setStyle('display','block');
	$(div_arrays[current]).fade(1);
}

function setScrollerMethod(target){
	var TipsAnswers = new Tips($$('h3.atStart'),{ fixed: true, showDelay: 0, hideDelay: 0, className: 'tip', offsets: {'x': -280, 'y': 10} });
	var myScroller = new Scroller(target, {area: 80, velocity: 0.2});
	myScroller.start();
}


var scrollSpeed = 100;
var scrollHeight= 20;

function scrollStart(direction, divID, elementID){
	ourInterval = setInterval("move"+direction+"('"+divID+"')", scrollSpeed);
}

function scrollEnd(which){
	//document.getElementById(which).style.backgroundColor = origColor;
	clearInterval(ourInterval);
}
function moveUp(which){
	document.getElementById(which).scrollTop = document.getElementById(which).scrollTop - scrollHeight;	
}
function moveDown(which){
	//alert(which);
	document.getElementById(which).scrollTop+=scrollHeight;	
}


var newX        = 0;
var newY		= 0; 
var oldX 		= 520
var oldY 		= 320;
var imageB 		= new Array();
var loadedBig 	= new Array();
var busyBig		= false;
var galleryBig;
function setBigImage(folder, nr){
	imageB = [
		folder + nr
	];
	
	galleryBig 		= $('div_image')
	 
	if (!busyBig) {
		var galleryBigImgs = $$('#div_image img');
		if (galleryBigImgs.length > 0){
			galleryBigImgs.each(function(image) {
				var RemoveImage = new Fx.Tween($('div_image'), {duration:500, 
					onComplete: function(){
					image.destroy();	
					loadNewImage();
				},
				transition: Fx.Transitions.linear});
				RemoveImage.start('opacity', 0);															
			});
			busyBig = true;
		}else{
			galleryBig.setStyle('display', 'block');
			loadNewImage();	
		}
	}
}

function loadNewImage(){
	new Asset.images(imageB, {
		onProgress: function(i) {
			this.setStyles({
				'position': 'absolute',
				'opacity': 0
			});
			loadedBig[i] = this;
			newX = this.width;
			newY = this.height;
		},
		onComplete: function() {
			$('div_image').fade(1);
			$('div_image').setStyle('left', 110 + (520-newX)/2);
			//$('div_image').setStyle('top', 7);
			loadedBig[0].inject(galleryBig);
			var fxBG = new Fx.Morph($('div_imageBG'), {duration: 1000, transition: Fx.Transitions.Cubic.easeOut,onComplete: function() {
					ChangeAnim('opacity', loadedBig[0], 1, 500, Fx.Transitions.Cubic.easeOut);
				}});
			fxBG.start({
				'width': newX + 2,
				'height': newY + 2,
				'left': 109 + (520-newX)/2
			});
			busyBig  = false			
		}
	});
}

