// JavaScript Document
var minimalHeight = 820;
var minimalWidth = 1004;
var currentImage = '';

var isIE6  = (navigator.appVersion.indexOf("MSIE 6") != -1) ? true : false;

var SetTopShadowHeight = function(classname) {
	var divs = $('div.' + classname);			
	
	var theHeight;
	// Window dimensions:
	if (window.innerHeight) {
	theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
	theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) {
	theHeight=document.body.clientHeight;
	}

	if(theHeight)
	{

		var h = theHeight - minimalHeight;
			
		if (h > 15 )
			divs.css('height', (h-1) + 'px');
		else
			divs.css('height','14px');	
	}
}

var SetSiteWidth = function(classname) {
	var divs = $('div.' + classname);	
	if (divs.length <=0)
	return;
	
		var theWidth;
		
	if (window.innerWidth) {
	theWidth=window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
	theWidth=document.documentElement.clientWidth;
	}
	else if (document.body) {
	theWidth=document.body.clientWidth;
	}
	
	if (theWidth && theWidth > minimalWidth )
		divs.css('width',theWidth + 'px');
	else 
		divs.css('width','1004px');
}
		
var ChangeIdea = function(filename)
{
	$('#idea').css('background-image', "url('../"+filename+"')");
}

var ReplacePNG = function(classname, type)
{
	var imgs = $('img.'+classname);
	for(i=0; i<imgs.length; i++)
	{
		imgs[i].src = imgs[i].src.toLowerCase().replace('png', type);
	}
} 

var HideIdea = function()
{
	$('#idea').css('width', '0px');
	
}

var ShowIdea = function()
{

	var imgs = $('#idea');
	imgs[0].src = '';
}


var ChangePerson = function()
{
	var flash = $('.swf');
	if(flash.length >0)
	{
		flash[0].Play();
		HideIdea();
		return;
	}
	
	var imgOld = $('div.old');
	if(!isIE6){
		if (imgOld.length >0)
		{
			HideIdea();
			imgOldH = '820px';
			imgOld.animate({height: 0, marginBottom: 0}, 1000, function(){$(this).removeClass('old').
			addClass('new').
			animate({height: imgOldH, marginBottom: -820}, 1000 )});
			HideIdea();	
		}
	}
	else
	{
		imgOld.removeClass('old').addClass('new');
	}
}

var scrollDown = function(sl, context)
{
	var value = $("#" + sl).slider('option', 'value');
	if (value != null ){
		if (value >= 5) {
			$("#" + sl).slider('option', 'value', value - 5);
		}
		else {
			$("#" + sl).slider('option', 'value', 0);
		}		
	}
	if ($("#" + context).length > 0){
		var maxScroll = $("#" + context).attr("scrollHeight") - $("#" + context).height();
		var current  = $("#" + context).attr("scrollTop");
		if (current + maxScroll/20 > maxScroll ){		
			$("#" + context).animate({scrollTop: maxScroll},50);
		}
		else {
			$("#" + context).animate({scrollTop: current+maxScroll/20 }, 50);
		}
	}
}

var scrollUp = function(sl, context)
{
	var value = $("#" + sl).slider('option', 'value');
	if (value != null ){
		if (value <= 95) {
			$("#" + sl).slider('option', 'value', value + 5);
		}
		else {
			$("#" + sl).slider('option', 'value', 100);
		}		
	}
	if ($("#" + context).length > 0){
		var maxScroll = $("#" + context).attr("scrollHeight") - $("#" + context).height();
		var current  = $("#" + context).attr("scrollTop");
		if (current - maxScroll/20 < 0 ){
			$("#" + context).animate({scrollTop: 0 }, 50);
		}
		else {
			$("#" + context).animate({scrollTop: current-maxScroll/20 }, 50);
		}
	}
}