﻿$(document).ready(function(){
	//						  
});

$(window).load(function(){
						
	/*
	HOMEPAGE CAROUSEL BANNER
	*/
	$(".carousel ul li img").show();
	
	$(".carousel").jCarouselLite({
		mouseWheel: false,
		auto:3000,
		speed:1000,
		pause: "#CarouselPlayPause",
		btnGo: [".1", ".2", ".3", ".4", ".5"]
	});
	
	$(".1, .2, .3, .4, .5").click(function(){
		if($("#CarouselPlayPause").hasClass("pause_btn"))
		{
			$("#CarouselPlayPause").click();
		}
	});
	
	$("#CarouselPlayPause").click(function(){
		if ($(this).hasClass("pause_btn"))
		{
			$(this).removeClass("pause_btn");
		}
		else
		{
			$(this).addClass("pause_btn");
		}
		
		return false;
	});
	//	
	
	/*
	SELECTOR
	*/
	$('#transaction_type').msDropDown();
	$('#prop_type').msDropDown();
	$('.smallselect select').msDropDown();
	
	$("#main-selector-expander").click(function(){
		
		var CLOSEDFLAG = "main-selector-closed";										
		
		if($(this).hasClass(CLOSEDFLAG))
		{
			// open
			$("#main-selector-details").slideDown();
			$(this).removeClass(CLOSEDFLAG);
		}
		else{
			// close
			$("#main-selector-details").slideUp();
			$(this).addClass(CLOSEDFLAG);
		}
	});
	
	$("#code-selector-expander").click(function(){
		
		var CLOSEDCODEFLAG = "code-selector-closed";										
		
		if($(this).hasClass(CLOSEDCODEFLAG))
		{
			// open
			$("#code-selector-details").slideDown();
			$("h5.selector").slideUp();
			$(this).removeClass(CLOSEDCODEFLAG);
		}
		else{
			// close
			$("#code-selector-details").slideUp();
			$("h5.selector").slideDown();
			$(this).addClass(CLOSEDCODEFLAG);
		}
	});
	
	$("h5.selector").click(function(){
		$("#code-selector-expander").click();								
	});
	
	$("#selector_search").click(function(){
		$("#cod").val("");								 
	});
	
	
	/*
	PAGINATION fixes
	*/
	var last_pagination_element_top = $("div.pagination-wrap-top div.pagination-wrap  .r ul li:last");
	var last_pagination_element_bottom = $("div.pagination-wrap-bottom div.pagination-wrap  .r ul li:last");
	$(last_pagination_element_top).addClass("paglastright");
	$(last_pagination_element_bottom).addClass("paglastright");
	//
	
	
	/*
	PHOTO GALLERY
	*/
	$("#gallery-thumbs li a").click(function(){
		large_image_path = $(this).attr("href");
		extralarge_image_path = $(this).attr("rel");
		
		$("#large-image img").fadeOut("fast", function(){
									$("#large-image a").attr("href", extralarge_image_path);
									$(this).attr("src", large_image_path).fadeIn("fast");	
								 });
		
		$("#gallery-thumbs li a").removeClass("active");
		$(this).addClass("active");
		
		return false;
	});
	
	$("#gallery-thumbs li:first a").click();
	//
	
	
	/*
	PHOTO ZOOM
	*/
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value between 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
	
	/*
	OFF DETAILS FORM
	*/
	$("#off_details_form #trimite").click(function(event){
		event.preventDefault();	
		
		var nume 	= jQuery.trim($("#off_nume").val());
		var telefon = jQuery.trim($("#off_telefon").val());
		var email 	= jQuery.trim($("#off_email").val());
		var cod 	= jQuery.trim($("#off_cod").val());
		var mesaj 	= jQuery.trim($("#off_mesaj").val());
		
		if(nume == "" || telefon == "" || cod == "")
		{
			//alert ("Completeaza tot ce trebuie acolo!");
			$(".offer-contact-info-status").html("Vă rugăm completaţi toate câmpurile marcate cu (*). Mesajul NU a fost trimis.");
			$(".offer-contact-info-status").addClass("offer-contact-info-status-error");
			$(".offer-contact-info-status").slideDown("slow");
			setTimeout(function() {
				$('.offer-contact-info-status').slideUp('fast');
			}, 5000);
		}
		else
		{
			var data_string = "nume=" + nume + "&telefon=" + telefon + "&email=" + email + "&cod=" + cod + "&mesaj=" + mesaj + "&checked=true";

			$.ajax({
			  type: "POST",
			  url: $("#off_details_form").attr("action"),
			  data: data_string,
			  success: function() {
				$("#off_nume").val("");  
				$("#off_telefon").val("");  
				$("#off_email").val("");  
				$("#off_mesaj").val("");  
				
				$(".offer-contact-info-status").html("Vă mulţumim, mesajul a fost trimis şi veţi fi în curând contactat.");
				$(".offer-contact-info-status").removeClass("offer-contact-info-status-error");
				$(".offer-contact-info-status").slideDown("slow");
			  }
			 });
		}
	});
	
	/*
	SIDE BANNER ROTATOR
	*/
	var banner_rotator_length = $("#sidebanner-rotator li").length; 
	var rand_no = Math.floor(banner_rotator_length * Math.random());
	$("#sidebanner-rotator li").eq(rand_no).show();


});

