$(document).ready(function() {
	
	$('.lightbox').lightbox();
	
	var d = true
	$("#show-languages").click(function() {				
		if(d){
			$("#languages").fadeIn('slow', function() {
				$(this).show();							
			}); 
			d = false;
		}	
		else{					
			$("#languages").fadeOut('slow', function(){
				$(this).hide();	
			}); 
			d = true;
		}
	});	
			
			
	//Show map on hover
	$('#map').hover(function() { 
		$(this).css({"overflow": "visible"}).animate({
	        "top":"-300px"
	    }, 500);
	},function() {
	    $(this).animate({
	        "top": '0px'
	    }, 500, function(){
	    	$(this).css({"overflow": "hidden"});
	    });
	});    
	
	/*
	$('.slider')._TMS({
		duration:800,
		easing:'easeOutQuad',
		preset:'zabor',
		pagination:'.pagination',
		slideshow:7000,
		banners:'fromTop',
		waitBannerAnimation:false,
		pauseOnHover:true
	})
	*/		
			
	//Calculator	
	$('#calculate').submit(function() { 				//alert($(this).serialize()); return false;		
		
		$.post(vir_path+"ajax.php", 'p=GetSumm&' + $(this).serialize(), function(theResponse){  
			$("#result_calculation").html('Summ: '+$.trim(theResponse)+'');
		});	
		/*
		$.post(vir_path+"calculator.php", 'p=calculate&is_calculate=1&' + $(this).serialize(), function(theResponse){ 
			$("#result_calculation").html('<label>Summ: </label>'+$.trim(theResponse)+'');
		});				
		*/
		$("#result_calculation").show();
	  	return false;
	});
	

	$('#partners a').mouseover(function(event){
		$(this).stop().animate({
			opacity: 1
		}, 200);
	});
	$('#partners a').mouseout(function(event){
		if($(this).hasClass('active')) return;
		$(this).stop().animate({
			opacity: 0.4
		}, 400);
	});

	
	if($("#form").length > 0){	
	//Style form
	$("input:text, input:password, input:checkbox, input:radio, textarea, select").uniform();
	$(".file input:file").uniform({fileDefaultText: 'Not selected.', fileBtnText: 'Select image.'}); 
	}
	//---------------------------------------------------------------------------------
	//Set label width auto  http://www.jankoatwarpspeed.com/post/2008/07/09/Justify-elements-using-jQuery-and-CSS.aspx
	//---------------------------------------------------------------------------------
	var max = 0;
    $("label").each(function(){
        if ($(this).width() > max)
            max = $(this).width();   
    });
    $("label").width(max);
    	
	
	//$( "#datepicker" ).datepicker({ dateFormat: 'dd-mm-yy' });

	//On hover -  animate Read more btn
	$("#text").mouseenter(function() {
		$("img", this).animate({ "margin-left": "7px" }, 300)
	}).mouseleave(function() {
		$("img", this).animate({ "margin-left": "0px" }, 300);
	});

	//Ui to top
	/*
	var defaults = {
			containerID: 'moccaUItoTop', // fading element id
		containerHoverClass: 'moccaUIhover', // fading element hover class
		scrollSpeed: 1200,
		easingType: 'linear' 
		};
	*/
	
	//$().UItoTop({ easingType: 'easeOutQuart' });

	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// IMAGES
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	
	//When hover show zoom
	$('.zoom img').each(function() {
    $(this).hover(
        function() {
            $(this).stop().animate({ opacity: 0.5 }, 400);
        },
       function() {
           $(this).stop().animate({ opacity: 1.0 }, 400);
       })
    });


	
	
	/*
	$('a[rel^="prettyPhoto"]').prettyPhoto({
        theme: 'light_rounded', //theme: 'pp_default', // light_rounded / dark_rounded / light_square / dark_square / facebook /
        deeplinking: false,
        overlay_gallery: false,
        social_tools:'',
        show_title: false
    });
    */
    
    /*
	$('.anythingSlider').anythingSlider({
		 easing: "swing",                // Anything other than "linear" or "swing" requires the easing plugin
		 autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		 delay: 3000,                    // How long between slide transitions in AutoPlay mode
		 startStopped: false,            // If autoPlay is on, this can force it to start stopped
		 animationTime: 800,             // How long the slide transition takes
		 hashTags: true,                 // Should links change the hashtag in the URL?
		 buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
		 pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		 navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
	});
	*/

/*
    // Set starting slide to 1
			var startSlide = 1;
			// Get slide number if it exists
			if (window.location.hash) {
				startSlide = window.location.hash.replace('#','');
			}
			// Initialize Slides
			$('#slides').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				pagination: false,
				generatePagination: false,
				play: 0, //5000 era
				pause: 2500,
				hoverPause: true,
				slideEasing: "easeOutCubic",
				fadeEasing: "easeOutQuad",
				slideSpeed: 350,
				effect: 'slide, fade',
				crossfade: true,

				// Get the starting slide
				start: startSlide,
				animationComplete: function(current){
					// Set the slide number as a hash
					//window.location.hash = '#' + current;
				}
			});

*/
		
	
	/*
	$('#slide, #slide-gallery').photoShow({
			title: '',
			input: 'html',
			height: '450px',
			width: '590px',
			thumb_cols: 3, 
			thumb_rows: 3,
			start_view: 'photo',
			captions_visible: 'hover',
			controls: ['prev', 'autoplay', 'thumbs', 'next'],
			auto_play: false,
			auto_play_interval: 5000,
			auto_play_type: 'infinite',
			show_auto_play_timer: true,
			image_animation_duration: 650,
			of_text: 'of',
			theme: 'dark',
			
			modal_name : 'prettyPhoto',
			modal_group : true,
			modal_ready_callback : function(){ 			
				$('a[rel^="prettyPhoto"]').prettyPhoto({
			        theme: 'light_rounded', //theme: 'pp_default',   light_rounded / dark_rounded / light_square / dark_square / facebook  
			        deeplinking: false,
			        overlay_gallery: false,
			        social_tools:'',
			        show_title: false
			    });
			} 
		});		
	*/	
	
	
	/*
	
	$('#slider').nivoSlider({ 
		directionNavHide:false, 
		controlNav:false,
		effect:'fold'
	});
	*/
	
	
	
	
	/*
	//On hover images show zoom image
	$(".zoom").append("<span class='zoom-in'></span>");
	
	$(".zoom").hover(function(){
		$(this).find("img").stop().animate({opacity:0.6}, "normal")
	}, function(){
		$(this).find("img").stop().animate({opacity:1}, "normal")
	});
	*/
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// FORM
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	
	
	//Find all the input, textarea elements with title attributes and add hint to it
    $('input[title!=""], textarea[title!=""]').hint();
    
    //Focus automaticall first input element
    //$('.auto-focus:first').focus();    
    
    //Captcha
	$("#new_captcha").click(function(){ 
		var c_currentTime = new Date();
		var c_miliseconds = c_currentTime.getTime();						
		$("#captcha").attr('src', vir_path + 'includes/captcha/image.php?x='+ c_miliseconds);
		return false;
	});
	
	$("#search-hotel").click(function(){
		country = $("#country_s").val();	 
		city = $("#city").val();	
		location.href = vir_path + "hotels/"+country + "/"+city;
		/*
		$("#content .center").append('<img src="'+vir_path+'includes/css/images/loading.gif" alt="Loading..." id="loading" />');
		country = $("#country_s").val();	 
		city = $("#city").val();	 
		$.post(vir_path + '/ajax_search.php', {'country': country, 'city': city}, function(responseText) {
				$('#content .center').html(responseText);				
		});
		*/
	});
	
	//Active/Inactive hot destinations
	$('#hot_active').click(function() { 
		if($('#hot_active').is(':checked')) { 
			$("#hot").slideDown(1000);			
		}
		else{ 
			$("#hot").slideUp(1000);				
		}		
	})
	
	if($('#hot_active').is(':checked')) { 
		$("#hot").slideDown(1000); 				
	}
	else{ 
		$("#hot").slideUp(1000);						
	}
			
	
	//http://www.jankoatwarpspeed.com/post/2008/07/09/Justify-elements-using-jQuery-and-CSS.aspx
	var max = 0;
    $("label").each(function(){
        if ($(this).width() > max)
            max = $(this).width();   
    });
    $("label").width(max);
    
    
	
	
	
	/*
	$(".country").multiselect({selectedList: 2, noneSelectedText: 'Select a country', click: function(e){ 
	       if( $(this).multiselect("widget").find("input:checked").length > 1 ){ 
	       		alert("Only one select!")
	           return false;
	       } 
	   }	
	}).multiselectfilter();
	
	//Active/Inactive category
	$('#category_active').click(function() { 
		if($('#category_active').is(':checked')) { 
			$('.category_id').attr('disabled', 'disabled');  
			$(".category_id").multiselect("enable"); 	
			//$('.someElement').attr('disabled', 'disabled');			
		}
		else{ 
			$('.category_id').removeAttr('disabled'); 
			$(".category_id").multiselect("disable"); 		
			//$('.someElement').removeAttr('disabled');		
		}		
	})
	
	if($('#category_active').is(':checked')) { 
		$('.category_id').attr('disabled', 'disabled'); 
		$(".category_id").multiselect("enable"); 				
	}
	else{ 
		$('.category_id').removeAttr('disabled'); 
		$(".category_id").multiselect("disable"); 				
	}
	*/	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// MENU
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	$('#left li a').hover( function(){
		$(this).stop().animate({marginLeft:'2px'},900,'easeOutElastic');}, function(){
		$(this).stop().animate({marginLeft:'0px'},900,'easeOutElastic');}
	);
	
	
	//Superfish menu
	$('.sf-menu').superfish({
		animation: {height:'show'},   // slide-down effect without fade-in 
	    delay: 800,
	    autoArrows:  false,  
	});
	

	//$(".megamenu").megamenu();

	//Open-close
		$(".expand").hide();  
		$(".open-close").click(function(){  
			if ($(this).is(".current"))
			{
				$(this).removeClass("current");
				$(this).next(".expand").slideUp(400);
			}
			else
			{ 
				$(".expand").slideUp(400);
				$(".open-close").removeClass("current");
				
				$(this).addClass("current");
				$(this).next(".expand").slideDown(400);
		    }
		});


	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///// OTHER
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	//Cufon.replace('.button span, .submit', { hover: true});
	
	
	$('.scrollTop a').click(
		function (e) {
			$('html, body').animate({scrollTop: '0px'}, 800);
			return false;
		}
	);	
	
	
	//Make height of blocks equals
    function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height(); 
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.css("min-height", tallest+"px")//height(tallest);
	}
		  
    equalHeight($(".eqHeight, .eqHeight2"));
    
	
	
	
	
	$('.add-cart222').click(function() { 
		var product_link = this.id; 
		//var x = this.href;
		$.ajax({
			method: "get", url: vir_path+ "cart.php", 
			data: "p=add-cart&link="+product_link,
			
			beforeSend: function(){$(".loading").fadeIn("slow"); $("#cart-result").fadeOut("fast"); }, 	//show loading just when link is clicked
			complete: function(){ $(".loading").fadeOut("slow"); $("#cart-result").fadeIn("slow");}, 		//stop showing loading when the process is complete
			
			success: function(html){ 																						//so, if data is retrieved, store it in html					
				var myStringArray = html.split("###SEP###");																																				
				$("#cart-result").html(myStringArray[0]); 															//show the html inside .content div				
				
				//Update cart nr items
				if(myStringArray[1] =='insert')
				{
					nr_items = $("#cart #items").text();	
					nr_items++;	
					$("#cart #items").text(nr_items);	
				}								
												
			}
		});
		
		return false;
	});
			
				

	//Process contact form	
	$('#contact-form .error').hide(); 
	$("#contact-form button").click(function(){  
		$('.error').hide(); 
		
		var name = $("input#name").val(); 	name = name.replace("&", "&amp;");   
        if (name == "Name:") {  
	        $("#name_error").show();  
	        $("input#field_name").focus();     
	        return false;  
        }  
        
        var email = $("input#email").val();   	email = email.replace("&", "&amp;");   	
        if (email == "Email:") {  
	        $("#email_error").show();  
	        $("#field_email").focus();     
	        return false;  
        }  
               
        var message = $("#message").val();         message = message.replace("&", "&amp;");
        if (message == "Message:") {  
	        $("#message_error").show();  
	        $("input#field_message").focus();  
	        return false;  
        }  
       
        //Encode &
		//name = name.replace(/&/g, "%26"); 
		//email = email.replace(/&/g, "%26");     
		//message = message.replace(/&/g, "%26"); 
       
        var dataString = 'name=' + name + '&email=' + email + '&message=' + message;
		//alert (dataString); //return false;
		$.ajax({
		    type: "POST",
		    url: vir_path+"includes/send_email.php",
		    data: dataString,
		    success: function(x) {  alert(x)
		        $('#contact-form').html("<div id='message' style='color: green; text-align: center'></div>");
		        $('#message').html(x)
		        .append("<p></p>")
		        .hide()
		        .fadeIn(1500, function() {
		         	 //$('#message').append("<img id='checkmark' src='images/check.png' />");
		        });
		    }
		});
		return false;

    });  
	//end process form
	
	
	
	
	
	
	
	
	
	
	

    	

	

	

	
});


/*Banner */
$(window).load(function(){
	
	i=1;
	//Run all banners
    $('div[id^=banner]').each(function() { 
    	       
    	$(this).cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, scrollDown, etc...
			speed:    3000, //speed transition
	    	timeout:  6000, //pause between slide
	    	pause:  1, //pause on hover
	    	//random:  1, //random
	    	delay:  -1000*i, //set the number of milliseconds to add to the timeout value for the first slide, useful when you have several slideshows on the same page 
			sync:   0, //controls whether the slide transitions occur simultaneously
			//next:   '#next2', prev:   '#prev2' //btn Next, Prev - <a href="#" id="prev2">Prev</a>
	    	//next '.banner' //click on image will change slide to next
	    	//pager:  '#nav' //pagination: $('#s4').before('<div id="nav">').cycle
	    	//before:  onBefore,  after:   onAfter //callback
		});
    	
		i=i+3;
    });

});


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//For slider
function formatText(index, panel) {
	return index + "";
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// FORMS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//For hints in input
jQuery.fn.hint = function (blurClass) {
  	if (!blurClass) { 
    	blurClass = 'blur';
  	}

  	 return this.each(function () {
   	 	// get jQuery version of 'this'
    	var $input = jQuery(this),

    	// capture the rest of the variable to allow for reuse
      	title = $input.attr('title'),
      	$form = jQuery(this.form),
      	$win = jQuery(window);

    	function remove() {
      		if ($input.val() === title && $input.hasClass(blurClass)) {
        		$input.val('').removeClass(blurClass);
      		}
    	}

   	 	// only apply logic if the element has the attribute
   		 if (title) { 
      		// on blur, set value to title attr if text is blank
      		$input.blur(function () {
	       		 if (this.value === '') {
	          		$input.val(title).addClass(blurClass);
	        	}
      		}).focus(remove).blur(); // now change all inputs to title

      		// clear the pre-defined text when form is submitted
      		$form.submit(remove);
      		$win.unload(remove); // handles Firefox's autocomplete
    	}
  	});
};



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// MENU
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Accordeon Menu
function initMenu() {	
	//Home menu
	$('.accordeon ul').hide();
	$('.accordeon a.active').next().show();
	//$('.accordeon li:first a:first').addClass("active");
	$('.accordeon li a').hover(
		function() {
			$(".accordeon li a").removeClass("active");
			$(this).addClass("active");
			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('.accordeon ul:visible').slideUp('normal');
			checkElement.slideDown('normal');
			return false;
		}
	});	
}
$(document).ready(function() {initMenu();});

//Curs
function calc(curr_press,current)
{
    val=$('.'+curr_press).val(); 
    $('.inp_val').each(function(i) 
    {
        if(curr_press!=$(this).attr('name'))
        {
            rez=Math.round((val*current)/$(this).attr('curs')*100)/100;
            $(this).val(rez);
        }
    });
    
}



//Excerpt 
//Use: in ready: $('.excerpt').dotTrailsPro({length: 250, out_animation: "fade"});  
(function ($) {
    $.fn.dotTrailsPro = function (options) {
        var defaults = {
            length: 100,
            more: "Read More",
            less: "Less",
            ani_speed: 600,
            out_animation: "slide",
            expandable: true
        };
        var options = $.extend(defaults, options);
        $(this).each(function () {
            var $new_length = defaults.length - 3;
            var $og_string = $(this).html();
            if (defaults.expandable == false) {
                var $ihtml = $og_string.substr(0, $new_length) + '...'
            } else {
                var $temp_string = '<div class="proUnhidden">' + $og_string.substr(0, $new_length) + '... <a class="morebtn" href="#' + defaults.more + '">' + defaults.more + '</a></div>';
                var $ihtml = $temp_string + '<div class="proHidden" style="display:none;">' + $og_string + ' <a class="lessbtn" href="#' + defaults.less + '">' + defaults.less + '</a></div>'
            }
            $(this).html($ihtml)
        });
        $('.morebtn').click(function () {
            $(this).parent().fadeOut(defaults.ani_speed, function () {
                $(this).parent().children('.proHidden').slideDown(defaults.ani_speed) //era fadeIn
                
            })
        });
        $('.lessbtn').click(function () {
            if (defaults.out_animation == "slide") {
                $(this).parent().slideUp(defaults.ani_speed, function () {
                    $(this).parent().children('.proUnhidden').fadeIn(defaults.ani)
                })
            } else {
                $(this).parent().fadeOut(defaults.ani_speed, function () {
                    $(this).parent().children('.proUnhidden').fadeIn(defaults.ani)
                })
            }
        })
    }
})(jQuery);



//Get subcategories for selected category
function sel_subcategories()
{    	   
	$("#response_category").append('<img src="'+vir_path+'includes/css/images/admin/loading.gif" alt="Loading..." id="loading" />');
	category = $("#category").val();	
	$.post(vir_path + '/ajax.php', {'category': category, 'p': 'sel_subcategories'}, function(responseText) {
			$('#response_category').html(responseText); 
			$("#response_category select").uniform();
	});
}


//Get categories for selected company
function sel_categories()
{    	   
	$("#response_company").append('<img src="'+vir_path+'includes/css/images/admin/loading.gif" alt="Loading..." id="loading" />');
	company = $("#company").val();	
	$.post(vir_path + '/ajax.php', {'company': company, 'p': 'sel_categories'}, function(responseText) {
			$('#response_company').html(responseText); 		
			initMenu();
	});
}


function sel_city()
{    	   
	$("#response_city").append('<img src="'+vir_path+'includes/css/images/loading.gif" alt="Loading..." id="loading" />');
	country = $("#country").val();	
	$.post(vir_path + '/ajax.php', {'p' : 'cities', 'country': country}, function(responseText) {
			$('#response_city').html(responseText); 
			$("#response_city select").uniform();
	});
}



//http://snippets.dzone.com/posts/show/5925
var formatDate = function (formatDate, formatString) {
	if(formatDate instanceof Date) {
		var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
		var yyyy = formatDate.getFullYear();
		var yy = yyyy.toString().substring(2);
		var m = formatDate.getMonth();
		var mm = m < 10 ? "0" + m : m;
		var mmm = months[m];
		var d = formatDate.getDate();
		var dd = d < 10 ? "0" + d : d;
		
		var h = formatDate.getHours();
		var hh = h < 10 ? "0" + h : h;
		var n = formatDate.getMinutes();
		var nn = n < 10 ? "0" + n : n;
		var s = formatDate.getSeconds();
		var ss = s < 10 ? "0" + s : s;

		formatString = formatString.replace(/yyyy/i, yyyy);
		formatString = formatString.replace(/yy/i, yy);
		formatString = formatString.replace(/mmm/i, mmm);
		formatString = formatString.replace(/mm/i, mm);
		formatString = formatString.replace(/m/i, m);
		formatString = formatString.replace(/dd/i, dd);
		formatString = formatString.replace(/d/i, d);
		formatString = formatString.replace(/hh/i, hh);
		formatString = formatString.replace(/h/i, h);
		formatString = formatString.replace(/nn/i, nn);
		formatString = formatString.replace(/n/i, n);
		formatString = formatString.replace(/ss/i, ss);
		formatString = formatString.replace(/s/i, s);

		return formatString;
	} else {
		return "";
	}
}
