var showed = false;
$(function() {
	$("div#main-menu > ul li").bind("mouseover", function(){
		$(this).children("ul").fadeTo("fast", 0.9);
    })

    $("div#main-menu > ul li").bind("mouseleave", function(e){
		$(this).children("ul").fadeTo("fast", 0).hide();
    });

    $("div#main-menu > li > ul.sub").bind("mouseleave", function(e){
    	$(this).fadeTo("fast", 0).hide();
    });



	$("div#baloon").bind("click", function(e){
		$(this).hide();
		$("div#panorama").slideDown("fast");
		showed = true;
	}).hover(
		function(){
			if (!showed) $("div#baloon").fadeTo("fast", 0.9);
		},
		function(){
			if (!showed) $("div#baloon").fadeTo("fast", 0.1);
		}
	).css("opacity", "0.1");
	$("div#panorama").bind("click", function(e){
		$(this).slideUp();
		
		$(this).oneTime(500, function() {
			$("div#baloon").fadeTo("fast", 0.1);
			showed = false;
		});
	});
	
	if ($("ul.imageset li").html() != null){
		$("ul.imageset li").attr("rel", "prettyPhoto[gallery]");
		$("ul.imageset li").prettyPhoto({
			animationSpeed: "fast",
			theme: "dark_rounded"
		});
	}
});



function CheckEmptyness(val){
	return (val.length < 3) ? false : true;
}
function CheckInteger(val){
	if (val == "") return false;
	return (val != "" && parseInt(val) == val) ? true : false;
}
function CheckFloat(val){
	if (val == "") return false;
	return (val != "" && parseFloat(val) == val) ? true : false;
}
function CheckEmail(e){
	e = e.toLowerCase();
	var ch="@";
	var count=0;
	var error=false;

	for (var i=0; i<e.length; i++){
		if (e.charAt(i)==ch || e.charAt(i)=="."){
			error = (count==0) ? true : error;
			ch = (ch==".") ? 0 : ch;
			ch = (e.charAt(i)=="@") ? "." : ch;
			count=0;
			continue;
		}
		count++;

		if ((e.charAt(i)<"a" || e.charAt(i)>"z") && (e.charAt(i)<"0" || e.charAt(i)>"9") && e.charAt(i)!="_" && e.charAt(i)!="-"){
			error = true;
			break;
		}
	}
	error = (count==0) ? true : error;
	error = (ch==0) ? error : true;
	return !error;
}
function CheckRadio(val){
	return (val.length < 3) ? false : true;
}


function ParseCode(msg){
	var code = $(msg).find('code').text();
	var message = $(msg).find('message').text();
	switch(code){
	case '0':
		$('form#sendform').replaceWith(message);
	break;
	case '1':
		$("form#sendform :input:[value='']").attr('disabled', false);
		$("form#sendform :submit").attr('disabled', false);
		$('div#messages').html(message);
		$('div#messages').fadeIn(10);
	break;
	default:
	}
}

function str_replace (search, replace, subject ) { 
	if(!(replace instanceof Array)){ 
		replace=new Array(replace); 
		if(search instanceof Array){//If search    is an array and replace    is a string, then this replacement string is used for every value of search 
			while(search.length>replace.length){ 
				replace[replace.length]=replace[0]; 
			} 
		} 
	} 
	
	if(!(search instanceof Array))search=new Array(search); 
	while(search.length>replace.length){
		replace[replace.length]=''; 
	} 

	if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well. 
		for(k in subject){ 
			subject[k]=str_replace(search,replace,subject[k]); 
		} 
		return subject; 
	} 

	for(var k=0; k<search.length; k++){ 
		var i = subject.indexOf(search[k]); 
		while(i>-1){ 
			subject = subject.replace(search[k], replace[k]); 
			i = subject.indexOf(search[k],i); 
		} 
	} 

	return subject; 
}
