// JavaScript Document
var objLiHovered = null;
var lSubIn = false;

function checkHover() {
  if(objLiHovered/* && !lSubIn*/) {
    objLiHovered.find('ul').fadeOut('fast');
    objLiHovered = null;
  }
}

$(document).ready(
		function(){
			
			$('#header_pics').fadeIn(200);
		  
			$('#header_pics').innerfade({
				speed: 'slow',
				timeout: 5000,
				type: 'sequence',
				containerheight: '321px'
			});
			
			$('#gallery_pics').innerfade({
				speed: 'slow',
				timeout: 5000,
				type: 'sequence',
				containerheight: '150px'
			});
			
			$('#webcams').innerfade({
				speed: 'slow',
				timeout: 6000,
				type: 'sequence',
				containerheight: '130px'
			});
			
			/*$('#all_boards_banner').show();
			$('#all_boards_banner').innerfade({
				speed: 'slow',
				timeout: 6000,
				type: 'sequence',
				containerheight: '280px'
			});*/
			
			$('#ke_banner').show();
			$('#ke_banner').innerfade({
				speed: 0,
				timeout: 2000,
				type: 'sequence',
				containerheight: '300px'
			});
			
			$('li#about_snk').hover(function() {
				
				$(this).find('ul').fadeIn('fast');
				$(this).find('#hovno').fadeIn('fast');
				objLiHovered = null;
			}, function() {
				objLiHovered = $(this);
				objLiHovered.find('#hovno').fadeOut('slow');
				setTimeout(
					"checkHover()",
					50);
			});
			
			setTimeout("$('#sticker').fadeIn(300);", 150);
			
			$('#snk').fadeIn(300);
			$('#logo').fadeIn(600);
			
			$("#searchRight").focus( function() {
			  if ($(this).attr("value") == "Hledat...")
			    $(this).attr("value", "");}
			);
			
			$("#searchRight").blur( function() {
			  if($(this).attr("value") == "")
			    $(this).attr("value", "Hledat...");
			});
			
			// fb czech ozone
			$("#slider_fb_czech").hover( function() { 
			  $('#slider_fb_czech').animate({paddingLeft:'+=100'},0);
			  $('#slider_fb_czech').animate({right:'-=10'},200);
			  $('#slider_fb_czech_text').animate({right:'+=112'},200);
			}, function() { 
			  $('#slider_fb_czech').animate({right:'+=10'},200);
			  $('#slider_fb_czech').animate({paddingLeft:'-=100'},0);
			  $('#slider_fb_czech_text').animate({right:'-=112'},200);
			});
			
			// fb intl ozone
			$("#slider_fb_intl").hover( function() { 
			  $('#slider_fb_intl').animate({paddingLeft:'+=100'},0);
			  $('#slider_fb_intl').animate({right:'-=10'},200);
			  $('#slider_fb_intl_text').animate({right:'+=112'},200);
			}, function() { 
			  $('#slider_fb_intl').animate({paddingLeft:'-=100'},0);
			  $('#slider_fb_intl').animate({right:'+=10'},200);	
			  $('#slider_fb_intl_text').animate({right:'-=112'},200);
			});
			
			// kite shop
			$("#slider_shop").hover( function() { 
  			$('#slider_shop').animate({paddingLeft:'+=100'},0);
			  $('#slider_shop').animate({right:'-=10'},200);
			  $('#slider_shop_text').animate({right:'+=90'},200);
			}, function() { 
			  $('#slider_shop').animate({paddingLeft:'-=100'},0);
			  $('#slider_shop').animate({right:'+=10'},200);	
			  $('#slider_shop_text').animate({right:'-=90'},200);
			});
			
			// kitesurf.cz
			$("#slider_kitesurf").hover( function() { 
			  $('#slider_kitesurf').animate({paddingLeft:'+=100'},0);
			  $('#slider_kitesurf').animate({right:'-=10'},200);
			  $('#slider_kitesurf_text').animate({right:'+=104'},200);
			}, function() { 
			  $('#slider_kitesurf').animate({paddingLeft:'-=100'},0);
			  $('#slider_kitesurf').animate({right:'+=10'},200);	
			  $('#slider_kitesurf_text').animate({right:'-=104'},200);
			});
			
			$("#newslet_signup").focus( function() {
			  if ($(this).attr("value") == "zadejte email..")
			    $(this).attr("value", "");
			});
			
			$("#newslet_signup").blur( function() {
			  if($(this).attr("value") == "")
			    $(this).attr("value", "zadejte email.."); });
		}
	);

// maximalni delka textarea
function ismaxlength(obj){
  var mlength = obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : 500;
  if (obj.getAttribute && obj.value.length>mlength)
    obj.value=obj.value.substring(0,mlength)
}

function reactOnBlurField(obj) {
  var lField = document.getElementById('email1');
  lField.value = "hehe" + obj.value + "haha";
}

/**
 * Vyvola odeslani formulare s akci onchange
 */
function submitOnChange(aFormID, aParam) {
  aParam = aParam || "a";
  
  $("#"+aFormID).attr("action", $("#"+aFormID).attr("action") + "&onchange=" + aParam);
  //this.form.action = this.form.action+'&amp;onchange=a';
  document.getElementById(aFormID).submit();
}

/**
 * validace cisla
 */
function validateNumber(aField, aDecimal) {
  var lValue = aField.value;
  var lValidChars = '0123456789';
  var lDotUsed = !aDecimal;
  var lOneChar;
  
  for (var i = 0; i< lValue.length; i++) {
    lOneChar = lValue.charAt(i);
    
    if (i > 0 && (i < lValue.length - 1) && !lDotUsed && lOneChar == '.') {
      lDotUsed = true;
      continue;
    }
    
    if (lValidChars.indexOf(lOneChar) == -1) {
      //$("#"+aField.id).focus();
      return false;
    }
  }
  
  return true;
}
