$(document).ready(function(){
	var $scrollingDiv = $(".gBtnFix");			
	$(window).scroll(function(){			
		var wrapheight = $('body').height();

		var margin_top = 291;
		if($('.gBtnFix').hasClass('posHome')) {
			margin_top = 475;
		}

		if($(window).scrollTop()>margin_top){
			if(wrapheight>($(window).scrollTop() + $('.gBtnFix').height())) {
				$scrollingDiv
				.addClass("fixedPos");
			}
		} 
		else {
			$scrollingDiv
			.removeClass("fixedPos");
		}
	});

	checkCookie();
 	validTarget("a.new-window");

	if (screen.width>=960) {$('.meerkat').css('display','block');}
	$('.meerkat .close-meerkat').click(function() {
		if(!$(this).parent('div').parent('div').parent('.meerkat').hasClass('closed-box')){
			$('.meerkat-content').hide();
			$('.show-meerkat').css('marginRight','12px');
			$(this).hide();
			$('.meerkat').animate({height:'33px'},function(){$('.meerkat').addClass('closed-box');});

			Delete_Cookie();
			setCookieClosed();
		}		
		return false;
	});

	$('.meerkat .show-meerkat').click(function() {
		if($(this).parent('div').parent('div').parent('.meerkat').hasClass('closed-box')){
			$('.meerkat-content').show();
			$('.show-meerkat').css('marginRight','0px');
			$('.close-meerkat').show();
			$('.meerkat').animate({height:'135px'});
			$('.meerkat').removeClass('closed-box');
			Delete_Cookie();
			setCookieOpen();
		}		
		return false;
	});

function Delete_Cookie() {
username=getCookie('gxsolutions');
if (username!=null && username!="")
{
document.cookie = "gxsolutions=; expires=Thu, 01-Jan-70 00:00:01 GMT;path=/";
}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookieClosed()
{
//alert("zatvaram");
document.cookie="gxsolutions=closed;max-age=3600;path=/";
}

function setCookieOpen()
{
//alert("otvaram");
document.cookie="gxsolutions=open;max-age=3600;path=/";
}

function checkCookie()
{
username=getCookie('gxsolutions');
//alert(username);
if (username!=null && username!="")
  {
	if(username=="closed"){
	$('.meerkat').addClass('closed-box');
	$('.meerkat').css('height','33px');
	$('.show-meerkat').css('marginRight','12px');
	$('.close-meerkat').hide();
	}
	else{
	$('.meerkat').removeClass('closed-box');
	$('.meerkat').css('height','135px');
	$('.close-meerkat').show();
	$('.show-meerkat').css('marginRight','0px');
	}
  }
}




	$('.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(){
	$('.meerkat').meerkat({
		background: '#999999',
		height: '120px',
		width: '100%',
		position: 'bottom',
		close: '.close-meerkat',
		dontShowAgain: '.dont-show',
		animationIn: 'slide',
		animationSpeed: 500,
		removeCookie: '.reset'
	});
});*/

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*/
	});
}
