﻿/* NCC main JS
 * Dependencies: jQuery 1.2.6
 * @author : Isotop AB
 */


 var hasFlash = true;
 $(window).load(function() {
     if (document.getElementById('htmlVersion')) hasFlash = false;

     $("#topmodules").find(".content startpage-puff-content").find("p").each(function() {

     var h = $(this).height() + 5;
     $(this).parents(".content").find(".opac-bg-bottom opac-bg-bottom-fixed-height").attr("style", "height:" + h + "px;");
        
     });
     $("#firstFilterDropDown a").click(function() {
         $("#region-dropdown ul").toggle();
     });
 });    
 
function thisMovie( movieName )
{
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function openDashboard( id )
{
	dashboardControl.show($('#SectionPuff712'));
}

 
 function DashboardControl()
 {
	this.root = null;
	this.closeBtn = null;
	this.currentBoard = null;
	this.bgPlate = null;
	this.currentSectionImg = null;
	this.allowedToBeClosed = true;
	this.onInit = null;
	
	this.init = function(r)
	{
		this.root = r;
		this.closeBtn = this.root.find('.close');
		this.bgPlate = $('#blackBgPlate');
		this.bgPlateContainer = $('#blackBgPlateContainer');
		
		_parent = this;
		this.closeBtn.click(function(){
			dashboardControl.hide();
		});
		if(this.onInit != null)
		    this.onInit();
		this.onInit = null;
	}

	this.show = function(boardSelector, sectionImg) {
	    if (this.root == null) {
	        this.onInit = function() { this.show(boardSelector, sectionImg); };
	        return;
	    }
	    board = $(boardSelector);
	    //alert(hasFlash + " " + board);
	    if (hasFlash) {
	        //alert(this.bgPlate + "" +  board);
	        this.root.show();
	        this.currentBoard = board;
	        //board.show();
	        this.bgPlateContainer.show();
	        this.bgPlate.show();
	        //board.SlideInLeft('1000');
	        $(board).show("slow");


	        return;
	    }
	    else {

	        if (!this.currentBoard) {
	            this.root.show();
	            this.bgPlateContainer.show();
	            this.bgPlate.show();
	            this.currentBoard = board;
	            this.currentSectionImg = sectionImg;
	            this.allowedToBeClosed = false;
	            setTimeout('dashboardControl.allowedToBeClosed = true', 650);
	            this.currentSectionImg.fadeIn('slow');
	            board.show();
	        }
	    }
	}
	
	this.hide = function()
	{
		if(hasFlash)
		{
			thisMovie("startpageApp").closeSection();
			//this.currentBoard.hide();
			this.currentBoard.hide();
			this.bgPlateContainer.hide();
			this.bgPlate.hide();
			this.root.hide();
			return;
		}
	
	
		if(!this.allowedToBeClosed)
			return;
	
		if(this.currentBoard)
		{
			this.currentBoard.hide();
			
			if(this)
			    this.currentSectionImg.hide();
		}
		this.root.hide();
		this.bgPlateContainer.hide();
		this.bgPlate.hide();

		this.currentBoard = null;
		
		
		currentSelection.find('.section-img').css('opacity','1');
		currentSelection.find('.section-img').css('filter','alpha(opacity=100)');
		currentSelection.find('a').hide();
	}
 }
 
 var dashboardControl = new DashboardControl();
 
 // html version
 
var currentSelection = null;
$(document).ready(function(){ 

	$('#htmlVersion .section').each(function(){
		$(this).mouseover(function(){
			if(!dashboardControl.currentBoard)
			{
				$(this).find('.section-img').css('opacity','.60');
				$(this).find('.section-img').css('filter','alpha(opacity=60)');
				
				$(this).find('a').show();
			}
			
		});
		
		$(this).click(function(){
			
			if(!dashboardControl.currentBoard)
			{
				//alert('skriv');
				
				$(this).find('.section-img').css('opacity','.60');
				$(this).find('.section-img').css('filter','alpha(opacity=60)');
				
				$(this).find('a').show();
				
			}
			currentSelection = $(this);
		});
		
		$(this).mouseout(function(){
			if(!dashboardControl.currentBoard)
			{
				$(this).find('.section-img').css('opacity','1');
				$(this).find('.section-img').css('filter','alpha(opacity=100)');
				$(this).find('a').hide();
			}
		});
	});
});


