jQuery(document).ready(function($) {

	if($('#reservation-page').length) {
		$("form#form1").validate({
			errorLabelContainer: $("#form1 div.errors"),
			errorElement: "em",
			messages: {
				tbIme: {
					required: "Morate uneti ime i prezime."
				},
				tbTelefon: {
					required: "Morate uneti telefon.",
					number: "Neispravan telefon. Dozvoljeni su samo brojevi."
				},
				tbIme1: {
					required: "Morate dodati barem jednog putnika. Unesite ime."
				},
				tbPrezime1: {
					required: "Morate dodati barem jednog putnika. Unesite prezime."
				},
				tbEmail: {
					email: "Neispravan format email adrese."
				}
			}

		});
	} else {		
	if($('.price-wrapper').length && $('.print-link').length == 0) {
		$('#main .item-listing').prepend('<a href="#" class="print-link floatright">Štampa</a>');
		$('.print-link').click(function() {
			window.print();
			return false;
		});	
	}
	
	$('#catalogue-box li:last').addClass('last');
	
	// Clear value of newsletter input field on focus
	$('#newsletterInput').focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	// And add default value if nothing entered
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	// Front page slider title replace
	Cufon.replace('#featured h2 a', {
		hover: true
	});
	
	// Price font replace
	Cufon.replace('.price strong');
	
	// Font replacement (IE Fix)
	Cufon.now();
	
	// Fade transition between simple and advanced search
	/*$('#search-box .more').click(function() {
		var target = $(this).attr('rel');
		$(this).parents('form').fadeOut('slow');
		$('#'+target).delay(800).fadeIn('slow');
	})*/
	
		// Call colorbox if gallery ID is set
		if($('#gallery').length) {
			// Lightbox for image gallery
			$("a[rel='gallery']").colorbox();
		}
		
		// Call colorbox if reservation-link class is set 
		if($('.reservation-link').length) {
			$('.reservation-link').colorbox();
		} else if($('.rentacar-link').length) {
			$('.rentacar-link').colorbox();
		}
	}
	
	// Call validation function if it is contact page
	if($('div').hasClass('js-page')) {
		//alert('contactpage');
		$('.js-page ul').hide();
		if($('div').hasClass('contact-page')) {
			$('.js-page ul:first').show().addClass('opened');
		}
		
		$('.js-page h2').css('cursor','pointer').click(function() {
			if($(this).next().hasClass('opened')) {
				$(this).next().slideUp().removeClass('opened');
			} else {
				$('.js-page ul').slideUp().removeClass('opened');
				$(this).next().slideDown().addClass('opened');
			}
			//$('.js-page ul').slideUp();
			//$(this).next().slideToggle();
		});
		
		$("form#contactForm").validate();
	}
	
	// If is home page call cycle function for featured items
	if($('body').attr('id') == 'home-page') {
		
		var tallest = 0;
		$('.item-listing').each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	$('.item-listing').height(tallest);
	
		$('#featured-items').cycle({
			timeout:       7000,  // milliseconds between slide transitions (0 to disable auto advance) 
			speed:         1000,  // speed of the transition (any valid fx speed value)
			height:        575,   // container height 
			sync:          1,     // true if in/out transitions should occur simultaneously 
			pause:         1,     // true to enable "pause on hover"
			prev:		   '#prev', 
		    next:		   '#next'
		});
	}
	
	jQuery(".tab:not(:first)").hide();

	//to fix u know who
	$(".tab:first").show();
	$(".htabs li:first a").addClass("current");
	
	$(".htabs a").click(function(){
		stringref = $(this).attr("href").split('#')[1];
		$(".htabs a").removeClass("current");
		$(this).addClass("current");

		$('.tab:not(#'+stringref+')').hide();

		if ($.browser.msie && $.browser.version.substr(0,3) == "6.0") {
			$('.tab#' + stringref).show();
		}
		else 
			$('.tab#' + stringref).fadeIn();
		
		return false;
	});

	
});