// provedeni iniciacnich kroku po nacteni stranky
$(document).ready(function() {
	initLeftMenu();			// funkce pro leve menu
	initOrgStructure();		// funkce pro organizacni strukturu (strom)
	showMessage();			// funkce pro zobrazeni hlasky po vlozeni firmy
	initPrettyPhoto();		// funkce pro PrettyPhoto (vylepseny lightbox)
	initGmapList();			// funkce pro iniciaci Google Maps
	initWebCamRefresh();	// funkce pro iniciaci automatické obnovy webkamery
	initVirtProhBanner();	// funkce pro iniciaci banneru pro virtualni prohlidky na HP
});

function initGmapList() {
	if ($(".dsgVPListItem")) {
		$(".dsgVPListItem").mouseover(function () {
			$(this).children('div').removeClass('dsgVPNameInAct').addClass('dsgVPName');
			$(this).children('p').show();
		});
		$(".dsgVPListItem").mouseout(function () {
			$(this).children('div').removeClass('dsgVPName').addClass('dsgVPNameInAct');
			$(this).children('p').hide();
		});
	}
}

// overi flash v prohlizeci
function initFlashCheck() {
/*	var hasFlash = false;
	try {
		var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
		if(fo) hasFlash = true;
	} catch(e) {
		if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true;
	}
*/
}

// rozklikavaci menu vlevo pro cely web -> new jQuery style
function initLeftMenu() {
	$("#dsgMenu > li > a").click(function () {
		// zjistujeme, jestli nasleduje UL proto, abychom tomuto elementu dali 
		// na click RETURN FALSE a u ostatnich nechali standardni funkcnosti kliku na A HREF
		if ($(this).next().is('ul')) { 
			$(this).next('ul').slideToggle("fast");
			return false;
		}
	});
	$("#dsgMenu > li > ul > li > a").click(function () {
		if ($(this).next().is('ul')) { 
			$(this).next('ul').slideToggle("fast");
			return false;
		}
	});
}

// zobrazeni formulare pro vlozeni nove firmy
function addCompany() {
	if ($('#addCompanyForm')) {
		$('#addCompanyForm').fadeIn("slow");
	}
}

// zobrazeni hlasky o vlozeni nove firmy
function showMessage() {
	if ($('#okCompMessage')) { 
		$('#okCompMessage').fadeIn("slow").fadeOut("fast").fadeIn("slow").fadeOut("fast").fadeIn("slow");
	}
}

// klikaci organizacni struktura - strom
function initOrgStructure() {
	if ($(".expander")) {
		$(".expander ~ ul").hide();
		$(".expander").toggleClass('expanderClose');
		$(".expander").click(function () {
			if ($(this).next().is('ul')) { 
				$(this).next('ul').slideToggle("fast");
				$(this).toggleClass('expanderClose');
			}
		});
	}
}

function initPrettyPhoto() {
	$("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_square' }); /* light_square */
}

function initWebCamRefresh(){
	if ($('#camPhoto')) {
		$('#camPhoto').attr("src", '/webcam/current?'+new Date().getTime());
		setTimeout("initWebCamRefresh()",60000);
	}
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}	
function initVirtProhBanner() {
	if ($('#dsgVitProhBanner')) {	
	    if ($.browser.msie) {
		    $("#dsgVitProhBanner").animate({ backgroundPositionX: "-442px"}, 4900);
		    $("#dsgVitProhBanner").animate({ backgroundPositionX: "-120px"}, 5800);  
	    } else {
		    $("#dsgVitProhBanner").animate({ backgroundPosition: "-442px 0px"}, 4900);
		    $("#dsgVitProhBanner").animate({ backgroundPosition: "-120px 0px"}, 5800);  
	    }
	}
}
