var stop=1;
var kid=1;
var index=0;
var newkid;

jQuery(document).ready(function(){
		
		jQuery(".pPad input[type=checkbox]").click(function() {
			search_results(1);	
		});
		jQuery("#sZile input[type=checkbox]").click(function() {
			search_results(1);	
		});
		jQuery("#sTags input[type=checkbox]").click(function() {
			search_results(1);	
		});
		jQuery('#suport a').addClass('suport');
		jQuery(".passinp").focus(function() {
			if(jQuery(this).attr('type')=='text'){
				var np=this.cloneNode(true);
					np.type='password';
					np.value='';
				this.parentNode.replaceChild(np,this);
			}
			jQuery(np).focus();
			
		});
		// kids ?
		kids = jQuery('.slide_img').children().size();
		
	
	
});

jQuery(window).load(function () {
	// let`s play
	slider = setInterval("block();",5000);
});


function showmenu(id) {
	jQuery('.listLinks a').removeClass('selbul');
	
	clearInterval(slider);
	
	jQuery('.slide_img .info').fadeOut('slow');
	jQuery('.slidedet .info').fadeOut('slow');
	
	jQuery('#soldet_'+id).fadeIn(400);
	jQuery('#sol_'+id).fadeIn(400,function(){
		jQuery('#link_'+id).addClass('selbul');
	});
}

// scroll


var scrollWorking = false;

function block() {

	if(!scrollWorking) {
		// check scroll working
		scrollWorking = true;
		
		jQuery('.listLinks a').removeClass('selbul');
		// slide
		newkid = (kid==kids)?1:(kid+1);
		jQuery('#soldet_'+kid).fadeOut('slow');
		jQuery('#sol_'+kid).fadeOut('slow',function(){
			scrollWorking = false;
			if(kid==kids) kid=1;
			else kid++;
		});
		
		jQuery('#soldet_'+newkid).fadeIn(400);
		jQuery('#sol_'+newkid).fadeIn(400,function(){
			jQuery('#link_'+newkid).addClass('selbul');
		});
	
	}

}

function scroll_video_left() {
	if(stop==1){
		var test = jQuery('#VideoList ul').children().size();
		if (test % 1 == 0) {var test = test + 1;}
		stop=0;

		//alert(test);
		var left=jQuery('#VideoList ul').css('left');

		  jQuery('#VideoList ul').animate({
		    left: ((left=='0px')?'':'+=148')
		  }, 500, function() {
		  	stop=1;
		    // Animation complete.
		  });
	}
}
function scroll_video_right() {
	if(stop==1){
		var test = jQuery('#VideoList ul').children().size();
		test2=((-148)*(test-4))+'px';
		stop=0;

			var left=jQuery('#VideoList ul').css('left');
	  jQuery('#VideoList ul').animate({
	    left: ((left==test2)?'-=0':'-=148')
	  }, 500, function() {
	  		stop=1;
	    // Animation complete.
	  });
	}

}

function changeTabs(id){
	jQuery(".cruiseTabs").fadeOut('fast');
	jQuery("#"+id).fadeIn('fast');
	
	jQuery("ul.cTabs li a").removeClass("seltab"); //Remove any "active" class
	jQuery("#tab"+id).addClass("seltab"); //Add "active" class to selected tab
}
function changeExpert(id){
	jQuery(".detalii_expert").fadeOut('fast',function(){
		jQuery("#tab"+id).fadeIn('fast');
	});
	
	
	jQuery("ul.Etabs li a").removeClass("selexpert"); //Remove any "active" class
	jQuery("#atab"+id).addClass("selexpert"); //Add "active" class to selected tab
}

function search_results(page){
	var porturi = '';
	var nr=1;
	jQuery('.pPad input:checked').each(function(){
		porturi += (nr==1?'':',')+(jQuery(this).val());
		nr++;
	});
	var zile = '';
	var nr=1;
	jQuery('#sZile input:checked').each(function(){
		zile += (nr==1?'':',')+(jQuery(this).val());
		nr++;
	});
	var tags = '';
	var nr=1;
	jQuery('#sTags input:checked').each(function(){
		tags += (nr==1?'':',')+(jQuery(this).val());
		nr++;
	});
	var destinatie = jQuery("select[name='results-dest']").val();
	var linie = jQuery("select[name='results-linie']").val();
	var dataplecarii = jQuery("select[name='results-data']").val();
	jQuery.post('ajax.search.results.php',
	{
		port: porturi,
		destinatie: destinatie,
		linie: linie,
		dataplecarii: dataplecarii,
		zile: zile,
		tags: tags,
		page: page,
		ajax: 1
	},
	function(data)
	{
		jQuery('#cruise-results').html(data);
	}
	);
}
function portlist(){
	if(jQuery('.porturiExpand').is(':visible')) {
		jQuery('.porturiExpand').fadeOut('fast');
		jQuery(document).scrollTo('.meniu_rez ul','slow');
	}
	else {
		jQuery('.porturiExpand').fadeIn('fast');
		jQuery(document).scrollTo('.porturilist2','slow');
	}
}

function index_tags(id){
	jQuery("ul.tabs li a").removeClass("seltab"); 
	jQuery('ul.tabs li #tab'+id).addClass("seltab"); 
	jQuery(".tab_content").slideUp('slow'); 
	
	jQuery.ajax({
	type: "POST",
	url: "ajax.php?a=tag-croaziere",
	data: "ACTION=POST&id="+id,
	dataType: 'json',
	success: function(data)	{
			jQuery('.tab_content .tab_submenu').html(data['subtags']);
			jQuery('.tab_content .tab_desc h2').html(data['titlu']);
			jQuery('.tab_content .tab_desc p').html(data['text']);
			jQuery('.tab_content .tabs_of ul').html(data['list']);
			jQuery(".tab_content").slideDown('slow'); 
		}
	});
	
}
function index_subtags(id){
	jQuery.ajax({
	type: "POST",
	url: "ajax.php?a=tag-croaziere",
	data: "ACTION=POST&id="+id,
	dataType: 'json',
	success: function(data)	{
			jQuery('.tab_content .tab_submenu').html(data['subtags']);
			jQuery('.tab_content .tab_desc h2').html(data['titlu']);
			jQuery('.tab_content .tab_desc p').html(data['text']);
			jQuery('.tab_content .tabs_of ul').html(data['list']);
		}
	});
	
}
function selectTag(vall){
	if(jQuery('#sTags input[value="'+vall+'"]').is(':checked')){
		jQuery('#sTags input[value="'+vall+'"]').removeAttr('checked');
	}
	else jQuery('#sTags input[value="'+vall+'"]').attr('checked','checked');
	search_results(1);
}


function inp_header(){
	var destinatieID = jQuery('#dest_select').val();
	var portID = jQuery('#port_select').val();
	var dataplecareID = jQuery('#dataplecare_select').val();
	
	jQuery.post(URL+'ajax.php?a=inp_header',{
			destinatie: destinatieID,
			port: portID,
			dataplecare: dataplecareID
	},function(data){
		
		var options='<option value="">'+data['option-porturi']+'</option>';
		jQuery.each(data['port'],function(key,port){
			options+='<option '+((portID==port['id'])?'selected="selected"':'')+' value="'+port['id']+'">'+port['title'+data['lang']]+'</option>';
		});
		
		jQuery('#port_select').html(options);
		
		var options='<option value="">'+data['option-dataplecare']+'</option>';
		jQuery.each(data['dataplecare'],function(key,port){
			options+='<option '+((dataplecareID==port['val'])?'selected="selected"':'')+' value="'+port['val']+'">'+port['data']+'</option>';
		});
		
		jQuery('#dataplecare_select').html(options);
		
		var options='<option value="">- - -</option>';
		jQuery.each(data['nrzile'],function(key,port){
			options+='<option value="'+port['val']+'">'+port['data']+'</option>';
		});
		
		jQuery('#nrzile_select').html(options);
		
		
	},"json");
}


function popUp(link,width,height) {
	var link;
	window.open(link,'','status=1,scrollbars=1,width='+width+',height='+height+',resizable=1')
}
