/* TOP MENU*/ 
var nums = "";
var selNum = "";
var onDisplay = "";
var myImage = new Image();
var imageWidth = ""
var imgWidth = "";
var imgWidthMove = "";

 $(document).ready(function(){
   $(".mainNavigation li").click(function(event){
   $(".mainNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected");
   $(".mainRightColumn").css("display", "none");
      });
   $(".mainNavigation li").hover(function() {
   $(this).addClass("navigationHover");
	}, function() {
    $(this).removeClass("navigationHover");
	});
	
	
	$(".toppStart").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".mainNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".mainLeftColumn").css("display", "none");
   $(".startsida").css("display", "block");
   $(".textblockMain").css("display", "block");
   $(".huvud").css("display", "block");
           });
		   
	$(".toppText").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".mainNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".mainLeftColumn").fadeOut(300);
   $(".text").fadeIn(300);
    $(".textblockMain").css("display", "block");
   $(".mainRightColumn").css("display", "none");
           });

	
	$(".toppProjekt").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".mainNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".mainLeftColumn").fadeOut(300);
   $(".projektAvd").fadeIn(300);
   $(".textblockMain").css("display", "block");
   $(".mainRightColumn").css("display", "none");
           });
		   

		   
	$(".toppWebb").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".mainNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".mainLeftColumn").fadeOut(300);
   $(".webbprojekt").fadeIn(300);
   $(".textblockMain").css("display", "block");
   $(".mainRightColumn").css("display", "none");
	
           });
		   
	$(".toppWiki").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".mainNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
  $(".mainLeftColumn").fadeOut(300);
   $(".tom").fadeIn(300);
   $(".textblockMain").css("display", "block");
           });
	
	$(".toppKontakt").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".mainNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
  $(".mainLeftColumn").fadeOut(300);
   $(".tom").fadeIn(300);
   $(".textblockMain").css("display", "block");
           });
	
/* MENU ON STARTIN PAGE */ 
	$(".startpageNavigation li").click(function(event){
   $(this).removeClass("navigationSelected");
   
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
      });
        $(".startpageNavigation li").hover(function() {
        $(this).addClass("navigationHover");
        }, function() {
          $(this).removeClass("navigationHover");
        });

  $(".liProjekt").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".textblockMain").fadeOut(300);
   $(".projekt").fadeIn(300);
           });

  $(".liBloggat").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".t").fadeOut(300);
   $(".bl").fadeIn(300);
           });

$(".liRapporter").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".t").fadeOut(300);
   $(".ra").fadeIn(300);
           });
	
  $(".liForedrag").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".t").fadeOut(300);
   $(".fo").fadeIn(300);
           });

  $(".liPublicerat").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".t").fadeOut(300);
   $(".pu").fadeIn(300);
           });
		   	   
  $(".liAlla").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".textblockMain").fadeIn(300);
   });		   

  $(".liAllaText").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".t").fadeIn(300);
   });		   

   
     $(".liKontoret").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".textblockMain").fadeOut(300);
   $(".kontoret").fadeIn(300);
   });	

     $(".liHuvud").click(function(event){
   $(this).removeClass("navigationSelected");
   $(".startpageNavigation li").removeClass("navigationSelected");
   $(this).addClass("navigationSelected")
   $(".textblockMain").fadeOut(300);
   $(".huvud").fadeIn(300);
   });		   

     $(".galleryShow").click(function(event){
	 event.preventDefault();
   $(".galleryTheme").fadeIn(300);
   $(this).fadeIn(300);
   });

   // CLOSE GALLERY EVENT
   $(".galleryClose").click(function(event){
	 $(".main").css("display", "block");
	 	 $(".galleryTheme").css("display", "none");
	 	         
      });  
	
   
 });

 // OPEN IMAGE-GALLERY FOR SPECIFIC CATEGORY
 	function galleryShow(t,n) {
		$(".main").css("display", "none");
		$(".galleryTheme").fadeIn(300);
		nums = n;
		selNum = nums;
		onDisplay = t;
	
	if ($.browser.msie){
$("#galleryImage").css("position", "absolute");
$("#galleryImage").css("top", "50%");
$("#galleryImage").css("vertical-align", "middle");
	$(".cImgLeft").css("top", "50%");
	$(".cImgLeft").css("margin-top", "-50");
	$(".cImgRight").css("top", "50%");
	$(".cImgRight").css("margin-top", "-50");
	}
	
	// CREATE OVERVIEW-LIST
		bar = document.getElementById("galleryOverview");
		var baz = "";
		num = 1;
		for (var i = 0; i < nums; i++) {
		baz = "<img src='gallery/" + onDisplay + num + ".jpg' class='gallerySmall' id='ov" + onDisplay + num + "' onclick=\"moveTo('" + onDisplay + "', '" + num + "')\">" + baz;
		num = num + 1;	
		}
	
	// APPEND OVERVIEW-LIST TO ELEMENT
	bar.innerHTML = baz;       
	
	foobar = document.getElementById("galleryImage");
	
	// CALL FUNCTION TO DISPLAY NEW GALLERY IMAGE
	assembleDisplay();
	
	// SET REWIND-ARROW (LEFT) TO EMPTY
	foo = document.getElementById("cImgLeft");
	foo.setAttribute("src", "images/tom.gif");
	
	// IF THERE IS ONLY ONE IMAGE IN CATEGORY SET FWD-ARROW (RIGHT) TO EMPTY ASWELL
	if (nums == 1) {
	foo = document.getElementById("cImgRight");
	foo.setAttribute("src", "images/tom.gif");
	}
	
	// OTHERWISE SET FWD TO VISIBLE
	else {
	foo = document.getElementById("cImgRight");
	foo.setAttribute("src", "images/fwd.gif");
	}
	
	}

		function assembleDisplay() {
	// IF BROWSER IS IE WE NEED A WORK AROUND TO GET IMAGE WIDTH
	if ($.browser.msie){
	foobar.innerHTML="<img src='gallery/" + onDisplay + selNum + ".jpg' class='showGalleryIE' id='img" + onDisplay + selNum + "'>";
	transformWidthIE();
	
	// REASIGN IMAGE AND SET NEW CSS AFTER WIDTH-TRANSFORMATION:
	foobar.innerHTML="<img src='gallery/" + onDisplay + selNum + ".jpg' class='showGalleryIE' id='img" + onDisplay + selNum + "'>";
	$("#galleryImage").width(imgWidth);
	$("#galleryImage").css("left", "50%")
	$("#galleryImage").css("margin-left", imgWidthMove);
	$(".showGalleryIE").width(imgWidth);
	$(".showGalleryIE").css("left", "50%")
	$(".showGalleryIE").css("margin-left", imgWidthMove);
	$(".gallerySmall").css("border", "2px solid #fff");
	var getSmall = "ov" + onDisplay + selNum;
  $("#" + getSmall).css("border", "2px solid #ED3219");
	}

	// FOR ALL OTHER BROWSERS :
else {	
	myImage = new Image();
myImage.src = "gallery/" + onDisplay + selNum + ".jpg";
   
   // GET IMAGE WIDTH AND ASSIGN TO ELEMENT
   setTimeout(function() {myImage.onload = getWidth();
  foobar.innerHTML="<img src='gallery/" + onDisplay + selNum + ".jpg' class='showGallery'>"; 
  transformWidth();}, 100); 
  $(".gallerySmall").css("border", "");
  var getSmall = "ov" + onDisplay + selNum;
  $("#" + getSmall).css("border", "2px solid #ED3219");  
 }
}
	
	// IMAGE WIDTH TRANSFORMATIONS TO FIT WINDOW
	function getWidth() {
	imageWidth = myImage.width;
	}
		
	// TRANSFORMATION FOR IE-BROWSERS
	function transformWidthIE() {
	var theImg = "";
	theImg = document.getElementById("img" + onDisplay + selNum);
	imgWidth = theImg.width;
	if (imgWidth < 600) {
	imgWidthMove = (imgWidth / 2) + 20;
	imgWidthMove = imgWidthMove - (imgWidthMove * 2);}
	else {
	imgWidth = parseFloat("600");
	imgWidthMove = parseFloat("-320");
	}
	}
	
	// TRANSFORMATION FOR ALL OTHER BROWSERS
	function transformWidth() {
    if (imageWidth < 600) {
	$(".showGallery").width(imageWidth);
	moveLeft = (imageWidth / 2) + 20;
	moveLeftContainer = ((imageWidth + 200) / 2) + 20;
	$(".showGallery").css("margin-left", "-" + moveLeft + "px");
		}
	else
	{
	$(".showGallery").width(600);
	$(".showGallery").css("margin-left", "-320px");
	}
	}
	
	// FUNCTION TO JUMP TO A SPECIFIC IMAGE FROM OVERVIEW
	function moveTo(t,n) {
	onDisplay = t;
	selNum = n;
	selNum = parseFloat(selNum);
	foobar = document.getElementById("galleryImage");
	
	// CALL FUNCTION TO DISPLAY NEW GALLERY IMAGE
	assembleDisplay();
	
	foo = document.getElementById("cImgLeft");
	foo.setAttribute("src", "images/rwd.gif");
	if (selNum == 1){
	foo = document.getElementById("cImgRight");
	foo.setAttribute("src", "images/tom.gif");
		}
	
	}
	
	function fwdImg() {
	if (selNum > 0) {
   selNum = selNum - 1;
   foobar = document.getElementById("galleryImage");
	
	assembleDisplay();
	
	foo = document.getElementById("cImgLeft");
	foo.setAttribute("src", "images/rwd.gif");
	if (selNum == 1){
	foo = document.getElementById("cImgRight");
	foo.setAttribute("src", "images/tom.gif");}
	}
		}
	
		function rwdImg() {
	if (selNum < nums) {
	selNum = selNum + 1;
   foobar = document.getElementById("galleryImage");
   
   assembleDisplay();
   
	foo = document.getElementById("cImgRight");
	foo.setAttribute("src", "images/fwd.gif");
	if (selNum == nums){
	foo = document.getElementById("cImgLeft");
	foo.setAttribute("src", "images/tom.gif");}
	}
	
	}
