$(document).ready(function(){
 	validTarget("a.new-window");
			
	$('.main-menu li').hover(function() {
	  $(this).addClass('hover');
	}, function() {
	  $(this).removeClass('hover');
	});
	
	$('.referencie-list li').hover(function() {
	  $(this).addClass('hover-row');
	}, function() {
	  $(this).removeClass('hover-row');
	});
	
	$(".c2").hover(function() { $(".c2").addClass("hover"); }, function() { $(".c2").removeClass("hover"); });
	$(".c3").hover(function() { $(".c3").addClass("hover"); }, function() { $(".c3").removeClass("hover"); });
	$(".c4").hover(function() { $(".c4").addClass("hover"); }, function() { $(".c4").removeClass("hover"); });
	$(".c5").hover(function() { $(".c5").addClass("hover"); }, function() { $(".c5").removeClass("hover"); });
	$(".c6").hover(function() { $(".c6").addClass("hover"); }, function() { $(".c6").removeClass("hover"); });
	$(".c7").hover(function() { $(".c7").addClass("hover"); }, function() { $(".c7").removeClass("hover"); });
	$(".c8").hover(function() { $(".c8").addClass("hover"); }, function() { $(".c8").removeClass("hover"); });
	$(".c9").hover(function() { $(".c9").addClass("hover"); }, function() { $(".c9").removeClass("hover"); });
	
	//$(".c3").addClass("active");
	
	$('div.ponuka-programov .row').mouseover(function() {
		$('div.ponuka-programov .row.selectedRow').removeClass('selectedRow');
      	$(this).addClass('selectedRow');
      });
         
      $('.tooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 150,
		id: "tooltip"
	});
	
	$('.tooltip-orange').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 150,
		id: "tooltip"
	});
	 
	$('.tooltip').hover(function() {
		$('body').removeClass('orange-tooltip');
	});	
	$('.tooltip-orange').hover(function() {
		$('body').addClass('orange-tooltip');
	});              
			    
	kreaInput("body div.field input"); /* input boxes jquery effects */
	valideForm("form.contact-form"); /* form validation */
	
	$("a.fancy").fancybox({
		'titleShow' : true,
		'titlePosition' : 'inside',
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic'
	});
	$('.slideshow').cycle({ fx: 'scrollUp', cleartype:  true, cleartypeNoBg:  true });
	$("#toggler2").tabs("#toggler2 .toggler-content2", {tabs: 'span.zobrazit-viac', effect: 'slide', initialIndex: null});
	$("#toggler").tabs("#toggler .toggler-content", {tabs: 'h3', effect: 'slide', initialIndex: null});
	$("#toggler3").tabs("#toggler3 .toggler-content", {tabs: 'h2', effect: 'slide', initialIndex: null});
				
	$('#mycarousel').jcarousel({auto: 3, wrap: 'last', initCallback: mycarousel_initCallback});
});

function validTarget(handler) {
    $(handler).click(function(){
        window.open(this.href);
        return false;
    });
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(3);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(3);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
       
function kreaInput(handler) {
	/*
		USAGE:
		
			kreaInput(".content input");
				or
			kreaInput("input.select");
	*/
	
	/* default values, change if you need */
	var fromOpacity = "1"; /* set opacity of text */
	var toOpacity = "1"; /* set after-animation text opacity */
	var fromColor = $(handler).css('color'); /* take color from css */
	var toColor = "#000000"; /* set after-animation color */
	var animateTime = 100; /* animation smooth/length */
	var message = "";
					
	//$(handler).css({ opacity: fromOpacity }, animateTime);
	$(handler).bind('click focus', function() {
		message = ($(this).attr("title"));
		
		/* ak je v inpute default message, zmaze ju */
				if ( $(this).val() == message ) {$(this).val('');}
	});
	$(handler).blur(function() {
		/* ak je input prazdny, vyplni ho default message */
		if ( $(this).val() =="" ) {$(this).val(message);}
		
	});
}

function valideForm(handler) {
	/*jQuery.validator.addMethod("password", function( value, element ) {
		var result = this.optional(element) || value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value);
		if (!result) {
			element.value = "";
			var validator = this;
			setTimeout(function() {
				validator.blockFocusCleanup = true;
				element.focus();
				validator.blockFocusCleanup = false;
			}, 1);
		}
		return result;
	}, "Your password must be at least 6 characters long and contain at least one number and one character.");*/
	
	// a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
	jQuery.validator.addMethod("defaultInvalid", function(value, element) {
		return value != element.defaultValue;
	}, "");
	
	/*jQuery.validator.addMethod("billingRequired", function(value, element) {
		if ($("#bill_to_co").is(":checked"))
			return $(element).parents(".subTable").length;
		return !this.optional(element);
	}, "");*/
	
	jQuery.validator.messages.required = "";
	$(handler).validate({
		invalidHandler: function(e, validator) {
			/*var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field. It has been highlighted below'
					: 'You missed ' + errors + ' fields.  They have been highlighted below';
				$("div.error span").html(message);
				$("div.error").show();
			} else {$("div.error").hide();}*/
		},
		onkeyup: false,
		submitHandler: function() {
			form.submit();
			/*$("div.error").hide();
			alert("submit! use link below to go to the other step");*/
		}/*,
		messages: {
			password2: {
				required: " ",
		  		equalTo: "Please enter the same password as above"	
			},
			email: {
				required: " ",
				email: "Please enter a valid email address, example: you@yourdomain.com",
				remote: jQuery.validator.format("{0} is already taken, please enter a different address.")	
			}
		},
		debug:true*/
	});
}