/// <reference path="jquery-1.4.1-vsdoc.js" />
/// <reference path="swfobject-vsdoc.js" />

function siteplacement(){
	sbwidth = scrollbarWidth();
	wwidth=$(window).width()+sbwidth;
	if($('#supersize').length != 0){
			
		$('body').css("overflow","hidden");
		
			wheight=$(window).height()-187;
			windoww=$(window).width();
			nw=windoww/1650;
			nh=wheight/714;
			nheight=nw*714;
			nwidth=nh*1650;
			
			minheight=443;
			minwidth=1024;
			
			/*console.log($(window).height());
			console.log($(window).width());*/
			//alert("nw:"+nw+" nh:"+nh);
			
			//Bredde og høyde på bildet
			aspect=1650/714;
			
			
			
			w = $(window).width();
			h = w / aspect;
			if (h < wheight) {
				h = wheight;
				w = h * aspect;
			}
			if(wheight>=minheight){
			$('#supersize').css("width",w);
			$('#supersize').css("height",h);
				//alert(h);			
			}else{
				//alert(w+ " og "+ h);
				
				if(w<minwidth){
					$('#supersize').css("width",minwidth);
					$('#supersize').css("height",minheight);
					
					//alert(w+ " og "+ h);
					
					
				}else{
					$('#supersize').css("width",w);
					$('#supersize').css("height",h);
					
					//alert(wheight);
				}
				
				
			}
			//console.log(windoww +" : " +w);
			//alert(windoww);
			
			//Justering av bunnlinjen
			

			if(windoww<minwidth){
				$('body').css("overflow-x","auto");
				
			}else{
				$('body').css("overflow-x","hidden");

			}
			if(wheight<minheight){
				$('body').css("overflow-y","auto");
				
			}else{
				$('body').css("overflow-y","hidden");

			}
			test=0;

				if(wheight<minheight){
					nh=minheight/714;
					
				}
				if(windoww<minwidth){
					nw=minwidth/1650;
				}

			if(nw>nh){
	

			test=nw-nh;
			
			test=test*(-714);

			
				$('#footer').css("margin-top",test);

			}else{

				
			}
			$('#supersize img').css('left', (windoww - $('#supersize img').width()) / 2);
            $('#supersize img').css('top', (wheight - $('#supersize img').height()) / 2)


			
			
	}
			
			//Fikser plassering av topp og bunnlinje ved endring av størrelse på side
					
			if(wwidth<1014){
				$('#footer').css("background-position","5px 0px");
				$('#top').css("background-position","3px 0px");
				$('#frontpagetext').css("left","0px");
				
			}else{
				$('#footer').css("background-position","center");
				$('#top').css("background-position","center");
				nw=(wwidth-1014)/2;
				nw=nw-0;
				$('#frontpagetext').css("left",nw);
			}
	
	
	
}

$(document).ready(function() {
			siteplacement();
			
			$(function($) {
				var colors='rgba(0,0,0,0.5)';
				if ( $.browser.msie && $.browser.version <= 8.0 ){
					colors='#012032';
				
				}
				
					
			   var options = {
					//timeNotation: '12h',
					//am_pm: true,
					utc: true,
					fontFamily: 'DigitalICG, Times New Roman',
					fontSize: '36px',
					foreground: colors,
					utc_offset: 1
					//background: 'red'
				  }; 
			   $('#jclock1').jclock(options);
			   options = {
					//timeNotation: '12h',
					//am_pm: true,
					utc: true,
					fontFamily: 'DigitalICG, Times New Roman',
					fontSize: '36px',
					foreground: colors,
					utc_offset: 4
					//background: 'red'
				  }; 
			   $('#jclock2').jclock(options);
			   options = {
					//timeNotation: '12h',
					//am_pm: true,
					utc: true,
					fontFamily: 'DigitalICG, Times New Roman',
					fontSize: '36px',
					foreground: colors,
					utc_offset: 8
					//background: 'red'
				  };
				$('#jclock3, #jclock4').jclock(options);
//			   $('#jclock4').jclock(options);
			   options = {
					//timeNotation: '12h',
					//am_pm: true,
					utc: true,
					fontFamily: 'DigitalICG, Times New Roman',
					fontSize: '36px',
					foreground: colors,
					utc_offset: 9
					//background: 'red'
				  }; 
			   $('#jclock5').jclock(options);
			});
			
			
			if($('#supersize').length == 0){
				//alert($(window).height());
				w=$(window).height()
				if(w>891){
					hei=w-177;
					$('#middle').css("min-height",hei);
					
				}
			}
			
			$(window).resize(function() {
				siteplacement();
			/*sbwidth = scrollbarWidth();
			wwidth=$(window).width()+sbwidth;
			wheight=$(window).height()-187;
			
			nw=wwidth/1650;
			nh=wheight/714;
			
			calc_height=nw*714;
			clac_width=nh*1650;
			
			aspect=1650/714;
			w = $(window).width() + sbwidth;
			h = w / aspect;

			if (h < wheight) {
				h = wheight;
				w = h * aspect;
			}
			if(wheight>350){
			$('#supersize').css("width",w);
			$('#supersize').css("height",h);
			}else{
				//alert(w+ " og "+ h);
				if(w<830){
					$('#supersize').css("width",830);
					$('#supersize').css("height",360);
					
				}else{
					$('#supersize').css("width",w);
					$('#supersize').css("height",h);
				}
				
				
			}
			//Justering av bunnlinjen
			test=0;
			if(nw>nh && wheight>350){
			test=nw-nh;
			test=test*(-714);
			test=test-4;
				$('#footer').css("margin-top",test);
			}
			
			if(wwidth<1650 && nw>=nh){
				//alert ('her');
				height=wwidth/(1650/714);
				height=height-244+test;
				$('#frontpagetext').css("top",height);
			}*/
			
			/*if(wheight<calc_height){
			ftheight=250-(calc_height-wheight)+test;
		
			$('#frontpagetext').css("bottom",ftheight);
			}else{
				$('#frontpagetext').css("bottom",250);
			}
			
			
			
			
			if(wwidth<1650){
				wheight=$(window).height();
				height=wwidth/(1650/714);
				//$('#supersize').css("height",height);
				height=height-244;
				$('#frontpagetext').css("top",height);
			}*/
			/*else{
				$('#supersize').css("height",714);
				$('#frontpagetext').css("top",470);
				
			}*/
			
			//Fikser plassering av topp og bunnlinje ved endring av størrelse på side
			/*if(wwidth<1014){
				$('#footer').css("background-position","5px 0px");
				$('#top').css("background-position","3px 0px");
				$('#frontpagetext').css("left","-162px");
				
			}else{
				$('#footer').css("background-position","center");
				$('#top').css("background-position","center");
				nw=(wwidth-1014)/2;
				nw=nw-162;
				$('#frontpagetext').css("left",nw);
			}*/
			
			
			
		});
	
	
	$('.menu li').each(function(index) {
			aw=$(this).find("a").width();
			//alert($(this).width());
			//$(this).width(aw+64);
			
			
			w=aw+64;
			if(index==3){
				w=w-4;	
			}else if(index==2){
				w=w+2;	
			}else if(index==1){
				w=w-1;	
			}else if(index==0){
				w=w-4;	
			}
			
			/*if($(this).attr("class")=="last"){
				w=w+(w-117);
			}*/	
			
			/*quotient=w/13;
			multiplyer=Math.round(quotient);
			product=13*multiplyer;
			difference=w-product;
			padding=30+difference;
			w=w+difference+4;*/
			//alert(w);
			$(this).width(w)
			$(this).find(".li-hover").css("width",w);
			//alert($(this).find("a").css("padding-left"));
			/*$(this).find("a").css("padding-left",padding+"px");*/
			
			
			
    });

    // 4 boxes on frontpage hover
    $(".frontpage-box").hover(function() {
        $(this).addClass("frontpage-box-hover");
    },
    function() {
        $(this).removeClass("frontpage-box-hover");
    });
    
    /*$(".fp-box-bt").hover(function() {
        $(this).addClass("fp-box-bt-hover");
    },
    function() {
        $(this).removeClass("fp-box-bt-hover");
    });*/
    
    /*$("li").hover(function() {
    	$(this).fadeIn("slow")
    },
    function() {
        $(this).fadeOut("slow")
    });*/
    
    $(".menu li").hover(function() {
    	id=$(this).attr("id");
    	if($("#"+id+"-hover").hasClass("active") == false){
        $("#"+id+"-hover").fadeIn(300);
        }
    },
    function() {
        id=$(this).attr("id");
        if($("#"+id+"-hover").hasClass("active") == false){
        $("#"+id+"-hover").fadeOut(300);
        }
        
    });
    
    $(".menu li").click(function() {
    	window.location =$(this).find("a").attr("href");	
    });
    
    
    $(".employee-item").hover(function() {
    	id=$(this).attr("id");
        $("#"+id+"-info-hover").fadeIn(300);
        $("#"+id+"-text-info").addClass("emplayee-text-info-hover");
    },
    function() {
        id=$(this).attr("id");
        $("#"+id+"-info-hover").fadeOut(300);
        $("#"+id+"-text-info").removeClass("emplayee-text-info-hover");
    });
    
    
    $(".frontpage-box").hover(function() {
    	id=$(this).attr("id");
        /*$("#"+id+"-box-bt").addClass("fp-box-bt-hover");*/
        $("#"+id+"-box-bt-hover").fadeIn(300);
       
    },
    function() {
        id=$(this).attr("id");
        $("#"+id+"-box-bt-hover").fadeOut(300);
        /*$("#"+id+"-box-bt").removeClass("fp-box-bt-hover");*/
    });
    
    $(".product_box").hover(function() {
    	id=$(this).attr("id");
        $("#"+id+"_text").addClass("prod_text_hover");
    },
    function() {
        id=$(this).attr("id");
        selectedid=$("#selectedid").val();
        if(id!=selectedid){
        
        	$("#"+id+"_text").removeClass("prod_text_hover");
        }
    });
    
    
    // Menu left hover
    $(".menu-left li:not(.active)").hover(function() {
        $(this).addClass("active");
    },
    function() {
        $(this).removeClass("active");
    });

    // Hover effects on img tag
    $(function() {
        $(".imgHover")
        .mouseover(function() {
            var src = $(this).attr("src").match(/[^\.]+/) + "_hover.png";
            $(this).attr("src", src);
        })
        .mouseout(function() {
            var src = $(this).attr("src").replace("_hover", "");
            $(this).attr("src", src);
        });
    });
});

/* Google Maps integration -------------------------------------------------------------------------------------- */
function AttachGMap(address, infobox, id, form_id) {

	var geocoder = null;
	var map = null;

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById(id));

		// Add marker for store address
		var geocoder = new GClientGeocoder();
		var point = geocoder.getLatLng(address, function(point) {

			if (!point) {
				//alert(address + " not found");
				// address not found, make maps invisible
				$("#" + id).css("background", "#fff");

			} else {
				var marker0 = new GMarker(point);
				marker0.title = "";
				map.addOverlay(marker0);
				map.setCenter(point, 13);
				GEvent.addListener(marker0, "click", function() {
					// submit to maps.google.no
					document.getElementById(form_id).submit();
				});
			}

			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
		});
	}

	// hide copyrightinfo on the bottom. I did this because it was too big and went outside designated area.
	//$("#" + id + " .gmnoprint,#" + id + " > div:last").css("display", "none");
}



// disable selecting
// $.disableSelection(selector)
jQuery.fn.extend({
	disableSelection: function() {
		this.each(function() {
			this.onselectstart = function() { return false; };
			this.unselectable = "on";
			jQuery(this).css('-moz-user-select', 'none');
		});
	}
});

// check if page has visible scrollbar
// $.hasScrollbar()
jQuery.fn.hasScrollbar = function() {
	var scrollHeight = this.get(0).scrollHeight;

	//safari's scrollHeight includes padding
	if ($.browser.safari)
		scrollHeight -= parseInt(this.css('padding-top')) + parseInt(this.css('padding-bottom'));

	if (this.height() < scrollHeight)
		return true;
	else
		return false;
}

// get width of scrollbar (varies between browsers)
function scrollbarWidth() {
	var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
	// Append our div, do our calculation and then remove it 
	$('body').append(div);
	var w1 = $('div', div).innerWidth();
	div.css('overflow-y', 'scroll');
	var w2 = $('div', div).innerWidth();
	$(div).remove();
	return (w1 - w2);
}
