// JavaScript Document
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function changeColor(color,speed)
{
	speed = (speed)?speed:5000;
	color = (color && color<0)?false:color;
	if(!color){	
		colors = Array("#200000","#152000","#001520","#170020","#1a1400","#000000");
		rand = Math.ceil(6*Math.random()-1);
		color = colors[rand];
	}
	if(color){	
	    $("html").animate({ backgroundColor: color}, speed);	  
	}									  	
}

var inter;
$('#changeColor').click(function(){
								 $('#colorTable').toggle();									 
								 $('#colorTable a').click(function(){
																   changeColor($(this).attr("class"),1000);
																   $('#colorTable').fadeOut('fast');																	
																	return false;	
										});					
								 return false;
								 });
inter = setInterval(function(){changeColor();},10000);
var thisID = "";
var formError = true;

if (jQuery.browser.msie) {
  if(parseInt(jQuery.browser.version) >= 6) {    
  }
} 
$("#footerMenu a").click(function(){		
	if(thisID != $(this).attr("rel")){
		$("#footerMenu li div").slideUp({ duration: 1000, easing: "easeInSine"});
	  	$(this).prev("div").slideDown('normal');	   
		$(".footerContent[id!="+$(this).attr("rel")+"]").hide('slide', {direction: 'left'}, 300);
		$("#"+$(this).attr("rel")).show('slide', {direction: 'left',easing: 'easeOutBack'}, 500);
	}
	thisID = $(this).attr("rel");
	return false;
});
$("#cmsTabs a").click(function(){		
	if(thisID != $(this).attr("rel")){ 
		$(this).parent('li').parent('ul').children('li').removeClass('selected');
		$(this).parent('li').addClass('selected');
		$(".cmsTabContent[id!="+$(this).attr("rel")+"]").hide('slide', {direction: 'left'}, 300);
		$("#"+$(this).attr("rel")).show('slide', {direction: 'left',easing: 'easeOutBack'}, 500);
	}
	thisID = $(this).attr("rel");	
	return false;
});
$("#askOffer a").click(function(){$('#pakkumine').slideDown('fast');});

 var defaultValues = new Array();
  jQuery("#feedback input, #tekst,#regEmail").focus(function() {												
    if (!defaultValues[this.id]) {defaultValues[this.id] = this.value;}
    if (this.value == defaultValues[this.id]) {this.value = "";}
    jQuery(this).blur(function() {
		if (this.value == "") {this.value = defaultValues[this.id];}
    });
  }).hover(function(){jQuery(this).addClass("hover")},function(){jQuery(this).removeClass("hover");});    


jQuery("#post").keyup(function(){checkEmail(jQuery(this).attr("id"));});
jQuery("#feedback input, #feedback textarea").css("opacity",0.6);
jQuery("#feedback input, #feedback textarea").hover(function(){$(this).fadeTo('normal',0.9);},function(){$(this).fadeTo('normal',0.6);});
jQuery("#sendForm").click(function(){
								   if(!formError && jQuery("#post").val() && jQuery("#tekst").val())
								   {
									   jQuery("#sendForm").hide();
									   jQuery("#feedback .loader").show();
									   jQuery.ajax({
										   type: "POST",
										   url: "engine/feedback.php",
										   data: "do=send&email="+jQuery("#post").val()+"&name="+jQuery("#nimi").val()+"&content="+jQuery("#tekst").val(),
										   success: function(msg){
												jQuery("#feedback").html(msg);
										   }
										 });								   
									}									
									return false;
});
jQuery("#sendRegForm").click(function(){
								   if(jQuery("#regEmail").val())
								   {
									   jQuery("#regEmailForm").hide();
									   jQuery("#regFormCont .loader").show();
									   jQuery.ajax({
										   type: "POST",
										   url: "engine/feedback.php",
										   data: "do=send&email="+jQuery("#regEmail").val()+"&type=reg",
										   success: function(msg){
												jQuery("#regFormCont").html(msg);
										   }
										 });								   
									}									
									return false;
});
$('#editList li').hover(function(){
								 	$(this).addClass('hover');
									$('.blackEditList li').eq($('#editList li').index(this)).children('.ok').addClass('selected');
									$('.whiteEditList li').eq($('#editList li').index(this)).children('.ok').addClass('selected');
								 },function(){
									 $(this).removeClass('hover');
									 $('.editList li').children('.ok').removeClass('selected');
								});
$.preloadImages("./images/sendBtnHover.png","./images/blackBg.png");