function sTarget(){
	$(".online").attr("target","_blank");
	$(".facebook").attr("target","_blank");
	$("#co-z-projektem").attr("target","_blank");
	
}

function sHover() {
	$('#list li').hover(
	function(){$(this).addClass('hover');},
	function(){$(this).removeClass('hover');}
	);
	$('div.jcarousel-next').hover(
			function(){$(this).addClass('hover');},
			function(){$(this).removeClass('hover');}
			);
	$('.login #sub').hover(
			function(){$(this).addClass('hover');},
			function(){$(this).removeClass('hover');}
			);
	$('div.jcarousel-prev').hover(
			function(){$(this).addClass('hover');},
			function(){$(this).removeClass('hover');}
			);
	$('.list-wi li').hover(
	function(){$(this).addClass('hover');},
	function(){$(this).removeClass('hover');}
	);
}

function initInputLabelFromLabel(input_id, label_id) {
	var text = $(label_id).text();
	var input = $(input_id);
	input.attr('emptyText', text);
	
	if (!input.val()) {
		input.val(text);
	}

	input.focus(function() {
		if ($(this).val() == text) {
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).val(text);
		}
	});
}

function initLab(label__id) {
	var text = $(label__id).prev().text();
	var label__id1 = $(label__id);
	if (!label__id1.val()) {
		label__id1.val(text);
	}
	
	label__id1.focus(function() {
		if ($(this).val() == text) {
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).val(text);
		}
	});
	
}

function schk() {
	$('label a').each(
	function(){
		$(this).click(
		function(event){
			event.stopPropagation();

		}		
		).attr("target","_blank");
	}		
	);
	$("INPUT[type='checkbox']").each(function(i, el){
		$(this).hide();
		var spn = $('<span>').insertBefore(this);
		$(el).parent().addClass('click');
		if($(el).attr('checked')){ $(el).prev().addClass('click');}
		});
	/*$(".click").toggle(
			function(){
				 $(this).find('span').addClass('click');
				 $(this).find("INPUT[type='checkbox']").attr('checked',true);
				
			},
			function(){
				 $(this).find('span').removeClass('click');
				 $(this).find("INPUT[type='checkbox']").attr('checked',false);
			}
			
	);*/
	
	 $('.click').each(function() {
		 var _this = $(this);
		var span = _this.find('span');
		 var input = _this.find("INPUT[type='checkbox']");
		 if (input.is(':checked')) {
		 span.addClass('click');
		  }
		  _this.click(function(event) {
		  event.preventDefault();
		  if (input.is(':checked')) {
		  span.removeClass('click');
		  input.attr('checked', false);
		  } else {
		  span.addClass('click');
		  input.attr('checked', true);
		  }
		  });
		  }); 
	
}

function initInputLabelFromInput(input_id) {
	var text = $(input_id).val();
	$(input_id).val(text);
	$(input_id).focus(function() {
		if ($(this).val() == text) {
			$(this).val("");
		}
	});
	$(input_id).blur(function() {
		if ($(this).val() == '') {
			$(this).val(text);
		}
	});
}

function lght() {
	$('#send_error_link').click(
	function(){
		$('#kontakt').addClass('active');
		$('#send_error_popup').addClass('active');
	}
	);
	$('.jqmClose').click(
			function(){
				$('#kontakt').removeClass('active');
				$('#send_error_popup').removeClass('active');
			}
			);
	
	
}

function odl() {
	var lo = 250;
	var ta = $('.ac textarea');
	if (ta.length==0) return;
	var sp = $('#countChars span');
	var li = ta.val().length;
	if (li <= lo) {var limit = lo - li ;sp.html(limit);}
	else var limit = lo; 
	 ta.keyup(
	 function()
	 {
	  var count_chars = $(this).val().length;
	  if (count_chars > lo)
	  {
	  var new_value = $(this).val().substring(0, lo);
	  $(this).val(new_value);
	  }
	  sp.html(""+lo - $(this).val().length+"");
	  
	 });

}

function initialize() {
	jQuery("#list").jcarousel({
        scroll: 1
    });
	initInputLabelFromLabel(".login #email",".login #email_l");
	initInputLabelFromLabel(".login #pass",".login #pass_l");
	initLab('.login #signin_username');
	initLab('.login #signin_password');
	sHover();
// sTarget();
	schk();
	odl();
	lght();
// $('.nagr').innerfade({
// animationtype: 'slide',
// speed: 1050,
// timeout: 3000,
// type: 'sequence',
// containerheight: '1em'
// });
	// $('#stars-wrapper1').rating('www.url.php', {maxvalue:5, increment:.5});
	// $('#stars-wrapper1').rating('www.url.php', {maxvalue:6, increment:.5,
	// curvalue:1.5});
	 

}
$(document).ready(initialize);
