/*!
 * Mobile Interaction JavaScript
 * http://www.mobileinteraction.com
 *
 * Copyright 2010
 * No unauthorized use allowed
 */
 
/* IMAGE PRELOADER */
			
var preload_image_cache = [];
function preload_image(url) {
	var cacheImage = document.createElement('img');
	cacheImage.src = url;
	preload_image_cache.push(cacheImage);
}
			
/* POPUPS */

var popup_background_html_element = '#popup_background';

function popup_show(div){
	$(div).css('left',($(window).width()-$(div).width())/2);
	$(div).css('top',($(window).height()-$(div).height())/3);

	$(div).css('visibility','visible');
	$(popup_background_html_element).css('visibility','visible');
	//alert($(div));
}

function popup_hide(div){		
	$(div).css('visibility','hidden');
	$(popup_background_html_element).css('visibility','hidden');
}

function popup_map(div){
	var w = Math.round($(window).width() * 80 / 100);
	var maxh = Math.round($(window).height() * 80 / 100);
	var h = Math.round(w * 3 / 4);
	if(h > maxh) h = maxh;
		
	$("#popup_googlemaps").css("width",w);
	$("#popup_googlemaps").css("height",h);
	
	popup_show(div);
}

function show_case(div,index){	
	var casestr = CASES[index]; 
	$("#popup_case").css("background-image","url(gfx/case_popup/case_" + casestr + ".png)");
	popup_show(div);
} 
 
/* SPOTLIGHT SCRIPTS */
function spotlight_menubar_click(index){
	if(index >= SPOTLIGHT.length) return;
	spotlight_autoswitch_disable = true;
	spotlight_autoswitch_index = index;
	
	clearTimeout(spotlight_autoswitch_timeout_id);
	spotlight_autoswitch_timeout_id = setTimeout('spotlight_autoswitch_disable = false; spotlight_autoswitch();', 20000);
	
	spotlight_switch(index);
}

function spotlight_switch(index){
	var casestr = SPOTLIGHT[index];
	
	$("#spot_fadeout").stop(true, true);	
	
	$("#spot").css("background-image","url(gfx/headers/image_" + casestr + ".jpg)");
	
	$("#spot_fadeout").animate({opacity: 0.0}, 1000, 
		function(){
			$("#spot_fadeout").css("background-image","url(gfx/headers/image_" + casestr + ".jpg)");
			$("#spot_fadeout").css("opacity","1.0");
		}
	);			
		
	$("#menu_dot" + index).attr("src","gfx/general/dot_active.png");
	
	for(var i = 0; i < SPOTLIGHT.length; i++){
		if(i != index){
			$("#menu_dot" + i).attr("src","gfx/general/dot.png");
		}
	}
}
function fadein(id){
	$(id).stop(true,false);
	if($(id).css("opacity") == "1") $(id).css("opacity","0.0");
	$(id).animate({opacity: 1.0}, 500);
}
function fadeout(id){
	$(id).stop(true,false);
	$(id).animate({opacity: 0.0}, 500);
}



function spotlight_menubar_mouseover(index){
	if(index == spotlight_autoswitch_index) return;
	if(index >= SPOTLIGHT.length) return;
	$("#menu_dot" + index).attr("src","gfx/general/dot_hover.png");
}

function spotlight_menubar_mouseout(index){
	if(index == spotlight_autoswitch_index) return;
	if(index >= SPOTLIGHT.length) return;
	$("#menu_dot" + index).attr("src","gfx/general/dot.png");
}

function clickSpotlight(){
	window.location = "case";
}

var spotlight_autoswitch_index = -1; 
var spotlight_autoswitch_disable = false;
var spotlight_autoswitch_timeout_id = 0;

function spotlight_autoswitch(){
	if(spotlight_autoswitch_disable) return;
	
	if(spotlight_autoswitch_index < 0) spotlight_autoswitch_index = Math.round(Math.random() * 100);
	
	spotlight_autoswitch_index = ((spotlight_autoswitch_index+1)%spotlight_count);
	spotlight_switch(spotlight_autoswitch_index);
	spotlight_autoswitch_timeout_id = setTimeout('spotlight_autoswitch();', 7000);
}
