$(document).ready(function(){
	
	// external links
	$("a[rel='external']").click(function() {
		return !window.open($(this).attr("href"));
	});
	$('.hide-with-js').hide(); // use this class to hide the message "please open this link in new window"
	
	// fade in messages
	$('.successMsg').hide();
	$('.successMsg').fadeIn(1000);
	$('.errorMsg div').hide();
	$('.errorMsg div').fadeIn(1000);
	$('.warningMsg').hide();
	$('.warningMsg').fadeIn(1000);
	
	// non-clickable links
	$(".return-false").click( function() {
		return false;
	});
	
	
	// JUMP MENU
	$("select.jump-menu").change(function(x){
		var url = $("option:selected", this).attr("title");
		if (url.length) {
			window.location.href = url;
		}
	});
	
	
	// clear inputs
	/*$("#form-newsletter input, #form-search input").each(function(i){
		var inputValue = $(this).val();
		
		$(this).focus(function(){ 
			if ($(this).val()==inputValue) {
				$(this).val("");
			}
		});
		$(this).blur(function(){ 
			if ($(this).val()=="") {
				$(this).val(inputValue);
			}
		});
	});*/
	
	
	// ADD ANOTHER RECIPIENT
	$("#add-recipient").click(function(){
		var nr = $("#nr").val();
		var newNr = parseInt(nr) + 1;
		//alert(newNr);
		var recipientHtml = '\
			\
			<div class="ctrlHolder clearfix other'+newNr+'">\
				<label for="imagine'+newNr+'">'+ text_imagine +'</label>\
				<input type="file"  id="imagine'+newNr+'" name="hostess[imagine][]" value="" class="textInput" style="width: 120px;" />\
				<a href="#"  style="margin-left: 70px;" class="remove-recipient" rel="other'+newNr+'" onclick="removeRecipient(\'other'+newNr+'\'); return false;">'+text_remove +'</a>\
			</div>';
		//alert(recipientHtml);	
		
		$("#before-services").before(recipientHtml);
		$("#nr").val(newNr);
		
		//alert(newNr);
		return false;
	});
	//$text_recomanda[$selected_lang][friend_email]
	
	$(".remove-recipient").click(function(){
		var elem = $(this).attr("rel");
		removeRecipient(elem);
		return false;
	});
	
	
	$("#show_only_no_top select, #show_only_no_bottom select").change(function(){
		var formId = $(this).parent().parent().attr("id");
		document.getElementById(formId).submit();
	});
	
	$("#alt_par").hide();
	$("#alt_ochi").hide();
	
	$("#par").ready(function(){
		var val = $('#par').val();
		var length_options=  $('#par option').size();
		
		if (val == (length_options-1)){
			$("#alt_par").show();
		}
		else{
			$("#alt_par").hide();
		}
	});	
	
	$("#par").change(function(){
		var val = $('#par').val();
		var length_options=  $('#par option').size();
		
		if (val == (length_options-1)){
			$("#alt_par").show();
		}
		else{
			$("#alt_par").hide();
		}
	});	
	
	
	$("#ochi").ready(function(){
		var val = $('#ochi').val();
		var length_options=  $('#ochi option').size();
		
		if (val == (length_options-1)){
			$("#alt_ochi").show();
		}
		else{
			$("#alt_ochi").hide();
		}
	});	
	
	$("#ochi").change(function(){
		var val = $('#ochi').val();
		var length_options=  $('#ochi option').size();
		
		if (val == (length_options-1)){
			$("#alt_ochi").show();
		}
		else{
			$("#alt_ochi").hide();
		}
	});	
	
	
	// EVENIMENTE HOMEPAGE	
	$('#evenimente-homepage').prepend('<div class="ad-image-wrapper"></div><div class="ad-controls"></div>');
	var galleries = $('#evenimente-homepage').adGallery({
		slideshow: {
			//loader_image: 'images/adGallery/loader.gif',
			enable: false
		}
	});
	
	
	// GALERIE HOSTESS HOMEPAGE	
	$('#gallery-list').prepend('<div class="ad-image-wrapper"></div><div class="ad-controls"></div>');
	var galleries = $('#gallery-list').adGallery({
		slideshow: {
			//loader_image: 'images/adGallery/loader.gif',
			enable: false,
			display_back_and_forward: false
		}
	});
	$("#gallery-list a").click(function(){
		
		var elemDetails = $(this).parent().find("div.details");
		
		var name = $(".name", elemDetails).text();
		var location = $(".location", elemDetails).text();
		var masuri = $(".masuri", elemDetails).text();
		var img1 = $(".img1", elemDetails).text();
		var img2 = $(".img2", elemDetails).text();
		var linkDetalii = $(".link", elemDetails).text();
		
		$("#profile-details strong").text(name);
		$("#profile-details span.locatie").text(location);
		$("#profile-details span.masuri").text(masuri);
		$("#profile-images .left a").attr("href", linkDetalii);
		$("#profile-images .right a").attr("href", linkDetalii);
		$("#profile-images .left img").attr("src", img1);
		$("#profile-images .right img").attr("src", img2);
		$("#profile-images .left img").attr("alt", name);
		$("#profile-images .right img").attr("alt", name);
		
	});
	$("#gallery-details a").click(function(){
		
		var img = $("img", this).attr("src");
		img = img.replace(/thumb/g, "normal");
		$("#img-large").attr("src", img);
		
		return false;
	});
	
	
	// GALERIE HOSTESS DETALII
	
	
	// Fading Images
	$("#profile-images a img").fadeTo(1000, 0.80);
	$("#profile-images a").hover(
		function(){
			$("img", this).fadeTo(50, 1);
		},
		function(){
			$("img", this).fadeTo(50, 0.80);
		}
	);
	
});

function removeRecipient(itemClass) {
	$("."+itemClass).remove();
	
	var nr = $("#nr").val();
	var newNr = parseInt(nr) - 1;
	$("#nr").val(newNr);
	//alert(newNr);
}

/*
function get_selected_value(id_catp, id_cat, id_subcat, id_product_line){
	var nr = $('#location').val();
	//alert(nr);
	
	if (nr >= -1){
		$.ajax({
			type: "POST",
			url: "ajax_get_poze_hostess.php",
			data: {
				id: nr,
				id_catp: id_catp,
				id_cat: id_cat,
				id_subcat: id_subcat,
				id_product_line: id_product_line
			},
			
			success: function(data){
				$('#hostess_location').html(data);
			}
		});
	}
}*/




