﻿/* NCC main JS
 * Dependencies: jQuery 1.2.1
 * @author : Isotop AB
 */ 
 
 var hasFlash = false;
 $(window).load(function(){
	if(document.getElementById('htmlVersion')) hasFlash = false;
 });
 
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.init = function(r)
	{
		this.root = r;
		this.closeBtn = this.root.find('.close');
		this.bgPlate = $('#blackBgPlate');
		this.bgPlateContainer = $('#blackBgPlateContainer');
		
		_parent = this;
		this.closeBtn.click(function(){
			_parent.hide();
		});
	}
	
	this.show = function(boardSelector, sectionImg)
	{	
		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');
			
			
			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();
			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();
 
 $(document).ready(function(){ dashboardControl.init($('#dashboardContainer'));});
 
 
 // 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();
			}
		});
	});
});
