
$(document).ready(function() {

	/* OZNACOVANI POLOZEK --- */
    jQuery('ul li:last-child,ol li:last-child,td:last-child,th:last-child').addClass('last');
    jQuery('ul li:first-child,ol li:first-child,td:first-child,th:first-child').addClass('first');
  
	
	
	$("a[href^=http]").each(function(){
		if(this.href.indexOf(location.hostname) == -1) {
	      $(this).addClass('external'); 

	    }
	});

	$('a.external').click( function(e)
	{ 
		 window.open(this.href);return false;
	});
	
	//$('a[rel*=lightbox]').lightbox();
	$('a.colorbox').colorbox({
		/*'titleShow'     : false,
		'type'				: 'image'*/
		'maxHeight':'95%',
		'maxWidth':'80%',
		'photo':true,
		'title':' '
		
	});
	$('a.colorbox-iframe').colorbox({
	/*	'titleShow'     : false,
		'type'				: 'iframe'*/
		'maxHeight':'95%',
		'maxWidth':'800px',
		'title':' '
		
	});
	
	$('.confirm').click( function(e)
			{ 
				 return confirm("Opravdu?");
			});
	
	
	$('.sub-item').hide();
    $('.sub-sw').click(function() 
    {
    	var pos = this.href.indexOf('#')
    	if(pos)
    	{
	    	var locationS = this.href.substring(pos);
		    if(locationS.length)
		    { 
		    	$('.sub-item').hide();
		    	$(locationS).show(300);
		    	
		    }
			}    	
    	return true;
    });
    
    $('#gpe-logo-basket').hide();
    
    $('#ePay').change(function() 
    {
    	 	if($(this).val()=='GPE')
    	 		$('#gpe-logo-basket').show(200);
    	 	else
    	 		$('#gpe-logo-basket').hide(100);
    	return true;
    });
    
      
    var locationS = document.location.hash;
    if(locationS.length)
    { 
      $(locationS).show(300);
    }
    
    
    //form 
	
	$('input.inputEmail').change( function(e)
	{ 
		var reggy = new RegExp(/^([\w-]+(?:\.[\w-]+)*)\@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$|(\[?(\d{1,3}\.){3}\d{1,3}\]?)$/i);
		var email = $(this).val();
		
		$(this).css('backgroundColor','white');
		
		if (email.length == 0) 
		{
			return true;
		} else {
			if (!reggy.test(email)) 
			{
				$(this).css('backgroundColor','#FF8C00');
				return false;
			} else {
				return true;
			}
		}
		return false;
	})
	
	
	$('input.inputPhone').change( function(e)
	{ 
		var reggy = new RegExp(/^(\+\d{3})?\d{9}$/i);
		var phone = $(this).val();
		
		$(this).css('backgroundColor','white');
		
		if (phone.length == 0) 
		{
			return true;
		} else {
			if (!reggy.test(phone)) 
			{
				$(this).css('backgroundColor','#FF8C00');
				return false;
			} else {
				return true;
			}
		}
		return false;
	});
	
	/*cat menu*/
	catMenuHide(0);
	/*
	$('ul.cat>li>a').mouseover( function(e)
	{ 	
		if(e.shiftKey)
		{ 
			$(this).css('cursor','auto');
			return true;
		}
		
		if($(this).hasClass("ac"))
		{
			$(this).css('cursor','n-resize');
		}else{
			$(this).css('cursor','s-resize');
		}
		
	});*/
	$('ul.cat>li>a').click( function(e)
	{ 
		if(e.shiftKey)
		{ 
			document.location = $(this).attr('href');
			return false;
		}		
		if($(this).hasClass("ac"))
		{
			$(this).removeClass("ac");
			$(this).parent().find('ul').slideUp(500);
		}else{
			catMenuHide(500);
			$(this).addClass("ac");
			$(this).parent().find('ul').slideDown(500);
		}
		
		return false;
	});

});


function catMenuHide(time)
{
	if(time==0)
	{
		$('ul.cat ul').hide();
		$('ul.cat>li>a.ac').parent().children('ul').show();
	}else{
		$('ul.cat ul').slideUp(time);
		$('ul.cat>li>a').removeClass('ac');
	}
}
