LargeImage = {
	elm: "stort_billed",
	smallElm: "maleri_layout",
	
	show: function(){
		document.getElementById(this.elm).style.display ="block";
		document.getElementById(this.smallElm).style.display ="none";
	},
	hide: function(){
		document.getElementById(this.elm).style.display ="none";
		document.getElementById(this.smallElm).style.display ="block";
		document.getElementById(this.elm).style.backgroundColor = "#000000";
	},
	setBackground: function(color){
		document.getElementById(this.elm).style.backgroundColor = "rgb("+color+")";
	},
	loaded: function(){		
		var id = "painting_carpet";
		var elm = new HTMLobj(id);
		elm.fadeOut(100,5,30);
	}
}

ColorPicker = {
	slider: "",
	pickerSize: 265,
	saturation: 1,
	value: 0,
	
	init: function(){
		this.slider = YAHOO.widget.Slider.getHorizSlider("stort_billed_scale","stort_billed_scale_thumb",0,this.pickerSize);
		this.slider.subscribe("change",function(){ColorPicker.calcRGB()});
	},
	
	getH: function() {
        var h = (this.pickerSize - this.slider.getValue()) / this.pickerSize;
        h = Math.round(h*360);
        return (h == 360) ? 0 : h;
    },
    
    calcRGB: function(){
    	var hue = this.getH();
    	var rgb = this.hsv2rgb(hue,this.saturation,this.value);
		if(this.slider.getValue()==0)
			rgb = [0,0,0];
		if(this.slider.getValue()==this.pickerSize)
			rgb = [255,255,255];
    	//document.getElementById("testing").innerHTML = "hue:"+hue+" RGB:"+rgb+" pos:"+this.slider.getValue();
    	LargeImage.setBackground(rgb[0]+","+rgb[1]+","+rgb[2]);
		PaintingView.setBackground(rgb[0]+","+rgb[1]+","+rgb[2]);
		this.saturation = 0.54;
		this.value = 0.28;
    },
    
    hsv2rgb: function(h,s,v) { 
         var r,g,b,i,f,p,q,t;
         i = Math.floor((h/60)%6);
         f = (h/60)-i;
         p = v*(1-s);
         q = v*(1-f*s);
         t = v*(1-(1-f)*s);
         switch(i) {
             case 0: r=v; g=t; b=p; break;
             case 1: r=q; g=v; b=p; break;
             case 2: r=p; g=v; b=t; break;
             case 3: r=p; g=q; b=v; break;
             case 4: r=t; g=p; b=v; break;
             case 5: r=v; g=p; b=q; break;
         }
         return [this.real2int(r), this.real2int(g), this.real2int(b)];
     },
     
    real2int: function(n) {
        return Math.min(255, Math.round(n*256));
	}
}

MenuHider = {

	image: "",
	menu: "",
	smallSize: 540,
	bigSize: 608,
	smallImage: new Array(),
	bigImage: new Array(),
	status: "",
	lastPage: "",
	
	init: function(){
		this.image = new HTMLobj(PaintingImage.getID());
		this.menu = new HTMLobj("stort_billed_overskrift");
		var ratio = 0;
		if(this.image.getHeight()>this.image.getWidth()){
			ratio = this.image.getWidth()/this.image.getHeight();
			this.bigImage = [Math.floor(this.bigSize*ratio),this.bigSize];
			this.smallImage = [Math.floor(this.smallSize*ratio),this.smallSize];
		}
		else{
			ratio = this.image.getHeight()/this.image.getWidth();
			this.bigImage = [this.bigSize,Math.floor(this.bigSize*ratio)];
			this.smallImage = [this.smallSize,Math.floor(this.smallSize*ratio)];
		}
	},
	
	hide: function(){
		this.init();
		this.menu.displayHide();
		this.image.tweenTo(easeInQuad,this.smallImage,this.bigImage,7);
		document.getElementById("stort_billed_maleri").style.height = "623px";
		document.getElementById("stort_billed_skjul_text").innerHTML="Vis";
		document.getElementById("stort_billed_skjul_img").src="design/images/maleri/unread.gif";
		this.status = "hide";
		document.getElementById("stort_billed_knapper_skift").style.visibility = "hidden";
	},
	
	show: function(){
		this.image.tweenTo(easeInQuad,this.bigImage,this.smallImage,7);
		window.setTimeout(function(){
								document.getElementById("stort_billed_skjul_text").innerHTML="Skjul";
								document.getElementById("stort_billed_skjul_img").src="design/images/maleri/read.gif";
								document.getElementById("stort_billed_maleri").style.height = "555px";
								MenuHider.menu.displayShow();
						  },300);
		this.status = "show";
		document.getElementById("stort_billed_knapper_skift").style.visibility = "visible";
	},
	
	paint: function(url){
		if(this.lastPage!=url.href){
			(url.href.search(/hide=/gi)>=0)? this.status="show" : this.status="hide";
			this.lastPage = url.href;
		}
		
		if(this.status=="show")
			this.hide();
		else 
			this.show();
	}
}
