

jQuery(document).ready(function() {

	    jQuery('#mycarousel').jcarousel({
    	wrap: 'circular'
		, initCallback: mycarousel_initCallback
		//, itemVisibleInCallback: functie_element_vizibil
		//, beforeStart: functie_primul_element
		//, itemFirstInCallback: functie_primul_element
		, itemFirstInCallback:  mycarousel_itemFirstInCallback
		, itemVisibleInCallback: {
            onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation
        }
		,itemVisibleOutCallback: {
			//onBeforeAnimation: mycarousel_itemVisibleOutCallbackBeforeAnimation,
            onAfterAnimation:  mycarousel_itemVisibleOutCallbackAfterAnimation
        }
		, scroll:1
		, auto :6 /*seconds for autoscrool*/
		, animation: 1800
		, buttonNextHTML: null
		, buttonPrevHTML: null
		
    });
	
});


function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
    //display('Item #' + idx + ' is now the first item');
	//console.log(idx);
	jQuery('.jcarousel-control a').removeClass('jcarousel_link_selectat');
	jQuery('.jcarousel-control a[ord="'+idx+'"]').addClass('jcarousel_link_selectat');	
	//setam textul de pe altul de la poza
	$('#text_poza_carousel').html($(getCurrentCarouselItem()).children('img').attr('alt'));
};

function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
    // No animation on first load of the carousel
   // if (state == 'init') return;
	 x=idx%14;

	 if ( idx==1) {
		 		//console.log('aici '+idx+' '+$("#prima" ).css( "margin-top"));
				$("#prima" ).animate({
					marginTop: "-480",
				  }, 5500, function() {
					//carousel.('auto', '1');
					//alert("gata");
				  });
		 		}
				
			
    //jQuery('img', item).fadeIn('slow');
};


/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleOutCallbackBeforeAnimation (carousel, item, idx, state) {
	 
};
 
function mycarousel_itemVisibleOutCallbackAfterAnimation(carousel, item, idx, state) {
	 x=idx%14;	 
	if (x==0 || idx==1) {
			
		 		$("#prima" ).css( "margin-top", "0px" );
				//console.log(' a plecat primul '+idx+' '+$("#prima" ).css( "margin-top"));
		 		};
	if ((idx%12)==0) { carousel.scroll(1);}
};



function functie_primul_element(carousel)
{
 //$("#prima" ).css( "margin-top", "+=330" );
	$("#prima" ).animate({
		marginTop: "-480",
	  }, 5500, function() {
		//carousel.('auto', '1');
		// Animation complete.
	  });
	
}

function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
		
        /*carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));*/
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('ord')));
		jQuery('.jcarousel-control a').removeClass('jcarousel_link_selectat');
		jQuery(this).addClass('jcarousel_link_selectat');
        return false;
    });
	/*
    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });
	
    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });*/
};


var currSlide = 0;
function getCurrentCarouselItem(){
      $("ul#mycarousel li.jcarousel-item").each(function(){
        if ($(this).offset().left >= 0){
            currSlide = this;
            return false;
        }
      });
    return currSlide;
    }

	

function functie_element_vizibil(carousel) {
//console.log(carousel);
//console.log(getCurrentCarouselItem());

	//if (carousel.first==14)	jQuery('#mycarousel').jcarousel('scroll',1); 
	
	jQuery('.jcarousel-control a').removeClass('jcarousel_link_selectat');
	jQuery('.jcarousel-control a[ord="'+carousel.first+'"]').addClass('jcarousel_link_selectat');	
	//setam textul de pe altul de la poza
	$('#text_poza_carousel').html($(getCurrentCarouselItem()).children('img').attr('alt'));
	
};



function etaj_luminat(obj)
{
	et='';
	et=$(obj).attr('rel');
	if (et.length>0)
		{
			$('#bloc').attr('class', 'et_'+et);
			$("#lista_etaje li a[class*='etaj_text'] ").removeClass('etaj_text_selectat');
			$("#lista_etaje li a[rel='"+et+"'] ").addClass('etaj_text_selectat');
			
		}
}





 function initializeaza_harta() {
    var latlng = new google.maps.LatLng(46.782107,23.54256);
    var myOptions = {
      zoom: 13,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
	var marker = new google.maps.Marker({
        position: latlng, 
        map: map,
        title:"Amera Towers!"
    });   	
  }
  
  function valideaza_contact()
 {
	 $("#form_contact").validate(
	{
		rules:
		{
			 nume: {required:true }
			, telefon: { number:true, rangelength: [10, 10]}			
			, email:{email: true}
			, mesaj:{required:true }
	
		}
		, messages:
		{
			  nume: {required:"Introduceti numele"}
			, telefon: {number:"Introduceti numarul de telefon din 10 cifre", rangelength:"numarul telefonul trebuie sa aiba 10 cifre"}
			, email:{email:"Introduceti o adresa valida"}
			, mesaj: {required:"Mesajul este obligatoriu"}
		}
		, errorPlacement: function(error, element)
		{
			if(element.parent().children('label.error:visible').length == 0)
			{
				
				error.appendTo(element.parent());
			}
		}
		, success: function(element)
		{
			element.parent().children('label.error').remove();
		}
		, highlight: function(element)
		{
			//$(element).parents('div:first').addClass('bgerror');
			$(element).addClass('border_red');
		}
		, unhighlight: function(element)
		{
			//$(element).parents('div:first').removeClass('bgerror');
			$(element).removeClass('border_red');
		}
		, submitHandler: function() {salveaza_contact();}
	});
 
 } 
  
  function submit_formular_contact()
{
	// stergem toate erorile
	$('#form_contact label.error').remove();
	$('#form_contact').submit();
}
function salveaza_contact()
{
	$.ajax({
      url: "contact.ajax.php"
    , type: 'post'
	, cache: false
	, dataType:'json'
        , data:{
            op:'send'
            , nume: $('#nume').val()
			, email: $('#email').val()
			, telefon: $('#telefon').val()
			, mesaj: $('#mesaj').val()
        },
        success: function(response){
		
		if ( (response.status))
			{
			$('#nume').val('name');
			$('#email').val('e-mail');
			$('#mesaj').val('Introduceti mesajul');
			alert (response.message);
			}
			else alert (response.message);
        },
        onFailure: function(transport) {
            alert(transport);
        }
    });
	return false;

}



 function valideaza_utile()
 {
	 $("#form_utile").validate(
	{
		rules:
		{
			 nume: {required:true }
			, telefon: {required:true, number:true, rangelength: [10, 10]}			
			, email:{required:true, email: true}
			, data_itp:{required:true }
	
		}
		, messages:
		{
			  nume: {required:"Introduceti numele"}
			, telefon: {required:"Telefonul este obligatoriu", number:"Introduceti numarul de telefon din 10 cifre", rangelength:"numarul telefonul trebuie sa aiba 10 cifre"}
			, email:{required:"Introduceti adresa de email", email:"Introduceti o adresa valida"}
			, data_itp: {required:"Data ITP este obligatoriu"}
		}
		, errorPlacement: function(error, element)
		{
			if(element.parent().children('label.error:visible').length == 0)
			{
				
				error.appendTo(element.parent());
			}
		}
		, success: function(element)
		{
			element.parent().children('label.error').remove();
		}
		, highlight: function(element)
		{
			//$(element).parents('div:first').addClass('bgerror');
			$(element).addClass('border_red');
		}
		, unhighlight: function(element)
		{
			//$(element).parents('div:first').removeClass('bgerror');
			$(element).removeClass('border_red');
		}
		, submitHandler: function() {salveaza_utile();}
	});
 
 } 
 
   function submit_formular_utile()
{
	// stergem toate erorile
	$('#form_utile label.error').remove();
	$('#form_utile').submit();
}
function salveaza_utile()
{
	$.ajax({
      url: "utile.ajax.php"
    , type: 'post'
	, cache: false
	, dataType:'json'
        , data:{
            op:'send'
            , nume: $('#nume').val()
			, email: $('#email').val()
			, telefon: $('#telefon').val()
			, data_itp: $('#data_itp').val()
			, data_rca: $('#data_rca').val()
			, sasiu: $('#sasiu').val()
        },
        success: function(response){
		
		if ( (response.status))
			{
			$('#nume').val('name');
			$('#email').val('e-mail');
			$('#mesaj').val('Introduceti mesajul');
			alert (response.message);
			}
			else alert (response.message);
        },
        onFailure: function(transport) {
            alert(transport);
        }
    });
	return false;

}



 function valideaza_programari()
 {
	 $("#form_programari").validate(
	{
		rules:
		{
			 nume: {required:true }
			, telefon: {required:true, number:true, rangelength: [10, 10]}			
			, email:{required:true, email: true}
			, marca:{required:true }
			, model:{required:true }
			, combustibil:{required:true }
			
			, ora:{number:true}
	
		}
		, messages:
		{
			  nume: {required:"Introduceti numele"}
			, telefon: {required:"Telefonul este obligatoriu", number:"Introduceti numarul de telefon din 10 cifre", rangelength:"numarul telefonul trebuie sa aiba 10 cifre"}
			, email:{required:"Introduceti adresa de email", email:"Introduceti o adresa valida"}
			, marca: {required:"Marca este obligatorie"}
			, model: {required:"Modelul este obligatoriu"}
			, combustibil: {required:"Combustibilul este obligatoriu"}
			, ora: {number:"Introduceti un nume"}
		}
		, errorPlacement: function(error, element)
		{
			if(element.parent().children('label.error:visible').length == 0)
			{
				
				error.appendTo(element.parent());
			}
		}
		, success: function(element)
		{
			element.parent().children('label.error').remove();
		}
		, highlight: function(element)
		{
			//$(element).parents('div:first').addClass('bgerror');
			$(element).addClass('border_red');
		}
		, unhighlight: function(element)
		{
			//$(element).parents('div:first').removeClass('bgerror');
			$(element).removeClass('border_red');
		}
		, submitHandler: function() {salveaza_programari();}
	});
 } 

function submit_formular_programari()
{
	// stergem toate erorile
	$('#form_programari label.error').remove();
	$('#form_programari').submit();
}

function salveaza_programari()
{
	$.ajax({
      url: "programari.ajax.php"
    , type: 'post'
	, cache: false
	, dataType:'json'
        , data:{
            op:'send'
            , nume: $('#nume').val()
			, email: $('#email').val()
			, telefon: $('#telefon').val()
			, data: $('#data').val()
			, data_rca: $('#data_rca').val()
			, sasiu: $('#sasiu').val()
        },
        success: function(response){
		
		if ( (response.status))
			{
			$('#nume').val('name');
			$('#email').val('e-mail');
			$('#mesaj').val('Introduceti mesajul');
			alert (response.message);
			}
			else alert (response.message);
        },
        onFailure: function(transport) {
            alert(transport);
        }
    });
	return false;

}
