//popup
function popup_show(){
	$('#bghider').show();
	$('#popup').show('slow');
}

function popup_hide(){
	$('#bghider').hide();
	$('#popup').hide('slow');
}

//rezervation
function make_rezervation(car, image_prefix, car_id){

	$("#dialog").dialog({ width: 600, height: 320 });
	$("#dialog").dialog({ title: car })
	
	var html = '';
	html += '<form method="get" onsubmit="check_rezervation(); return false;">';
	html += '<center><table style="margin: auto">';
	html += '<tr><td rowspan="8" style="text-align: center;"><img src="files/car_rent/'+image_prefix+'/1.JPG" style="width: 300px; margin: 10px;"></td></tr>';
	html += '<!--<tr><td style="font-size: 12px; color: #336;">'+lang['car']+':</td><td><b style="font-size: 12px; color: #336;">'+car+'</b>--><input type="hidden" id="rez_car" name="rezervation_car" value="'+car+'"><input type="hidden" id="rez_car_id" name="rezervation_car_id" value="'+car_id+'"><!--</td></tr>-->';
	html += '<tr><td style="font-size: 12px; color: #336;">'+lang['from']+':</td><td><input id="date_from" name="date_from"></td></tr>';
	html += '<tr><td style="font-size: 12px; color: #336;">'+lang['to']+':</td><td><input id="date_to" name="date_to"></td></tr>';
	html += '<tr><td style="font-size: 12px; color: #336;">'+lang['name']+':</td><td><input name="name" id="rez_name"></td></tr>';
	html += '<tr><td style="font-size: 12px; color: #336;">'+lang['contact phone']+':</td><td><input name="contact_phone" id="contact_phone"></td></tr>';
	html += '<tr><td style="font-size: 12px; color: #336;">'+lang['email']+':</td><td><input name="email" id="email"></td></tr>';
	html += '<tr><td colspan="2" style="text-align: center;"><input class="button" type="submit" value="'+lang['make rezervation']+'"></td></tr>';
	html += '</table></center></form>';
	
	$('#dialog').html(html);
	
		var date = new Date();
	
		var t_day = date.getDate();
		if(t_day<10) t_day = "0"+t_day;
		
		var t_month = date.getMonth()+1;
		if(t_month<10) t_month = "0"+t_month
		
		var t_year = date.getFullYear();
	
		$("#date_from").datepicker({dateFormat: 'yy-mm-dd', minDate: t_year+'-'+t_month+'-'+t_day });
		$("#date_to").datepicker({dateFormat: 'yy-mm-dd', minDate: t_year+'-'+t_month+'-'+t_day });
	
}

function check_rezervation(){
	
	var url = "tiny.php?q=rezervation";
	url += "&rezervation_car="+$("#rez_car").val();
	url += "&rez_car_id="+$("#rez_car_id").val();
	url += "&date_from="+$("#date_from").val();
	url += "&date_to="+$("#date_to").val();
	url += "&name="+$("#rez_name").val();
	url += "&contact_phone="+$("#contact_phone").val();
	url += "&email="+$("#email").val();
	
	$.get(url, function(data){
	   alert(data);
	  //$('#dialog').dialog('close');
	 });
}



//car images
var show_image_current = 1;
var show_image_current_folder = 1;
var show_image_imagecount = 1;

function show_images(folder, imgcount){
	show_image_current = 1;
	show_image_current_folder = folder;
	show_image_imagecount = imgcount;
	
	$("#dialog").dialog({ width: 800, height: 600 });
	$("#dialog").dialog({ title: 'Galerie' })
	
	var html = '';
	
 
	if (navigator.appName=="Microsoft Internet Explorer"){
		 html = '<div id="show_image_bigimage_div" style="background: url(\''+folder+'1.JPG\') no-repeat center center; width: 100%; height: 600px;">&nbsp;';
	} else {
		  html = '<div id="show_image_bigimage_div" style="background: url(\''+folder+'1.JPG\') no-repeat center center; width: 100%; height: 100%;">&nbsp;';
	}
	html += '<div id="show_image_button_prev"  style="display: none; position: absolute; bottom: 0px; left: 0px; text-align: left; vertical-align: middle; width: 400px; height: 300px; cursor: pointer" onclick="show_images_prev(); return false;"><img src="style/malek/images/prev.png"></div>'
	html += '<div id="show_image_button_next"  style="position: absolute; bottom: 0px; right: 0px; text-align: right; vertical-align: middle; width: 400px; height: 300px; cursor: pointer" onclick="show_images_next(); return false;"><img src="style/malek/images/next.png"></div>'
	html += '</div>';
	
	$('#dialog').html(html);
}

function show_images_next(){
	if(show_image_current < show_image_imagecount){
		show_image_current += 1;
		$('#show_image_bigimage_div').css("background", "url('"+show_image_current_folder+show_image_current+'.JPG'+"') no-repeat center center");
		$('#show_image_button_prev').show('slow');
		if(show_image_current == show_image_imagecount) $('#show_image_button_next').hide('slow');
	}
}

function show_images_prev(){
	if(show_image_current>1){
		show_image_current -= 1;
		$('#show_image_bigimage_div').css("background", "url('"+show_image_current_folder+show_image_current+'.JPG'+"') no-repeat center center");
		$('#show_image_button_next').show('slow');
		if(show_image_current == 1) $('#show_image_button_prev').hide('slow');
	}
}



//galerie images
show_image_array_current = 1;
show_image_current_array = new Array();

function show_images_from_array(array, num){
	show_image_array_current = num;
	show_image_current_array = array;

	$("#dialog").dialog({ width: 800, height: 600 });
	$("#dialog").dialog({ title: 'Galerie' })
	
	var html = '';
	
 
	if (navigator.appName=="Microsoft Internet Explorer"){
		 html = '<div id="show_image_bigimage_div" style="background: url(\''+array[num]+'\') no-repeat center center; width: 100%; height: 600px;">&nbsp;';
	} else {
		  html = '<div id="show_image_bigimage_div" style="background: url(\''+array[num]+'\') no-repeat center center; width: 100%; height: 100%;">&nbsp;';
	}
	
	html += '<div id="show_image_button_from_array_prev"  style="display: none; position: absolute; bottom: 0px; left: 0px; text-align: left; vertical-align: middle; width: 400px; height: 300px; cursor: pointer" onclick="show_images_from_array_prev(); return false;"><img src="style/malek/images/prev.png"></div>'
	html += '<div id="show_image_button_from_array_next"  style="position: absolute; bottom: 0px; right: 0px; text-align: right; vertical-align: middle; width: 400px; height: 300px; cursor: pointer" onclick="show_images_from_array_next(); return false;"><img src="style/malek/images/next.png"></div>'
	html += '</div>';
	
	$('#dialog').html(html);
}

function show_images_from_array_next(){
		if(show_image_current_array[show_image_array_current+1]){
			show_image_array_current += 1;
			$('#show_image_bigimage_div').css("background", "url('"+show_image_current_array[show_image_array_current]+"') no-repeat center center");
			$('#show_image_button_from_array_prev').show('slow');
		}
		if(!show_image_current_array[show_image_array_current+1]) $('#show_image_button_from_array_next').hide('slow');
}

function show_images_from_array_prev(){
		if(show_image_current_array[show_image_array_current-1]){
			show_image_array_current -= 1;
			$('#show_image_bigimage_div').css("background", "url('"+show_image_current_array[show_image_array_current]+"') no-repeat center center");
			$('#show_image_button_from_array_next').show('slow');
		}
		if(!show_image_current_array[show_image_array_current-1]) $('#show_image_button_from_array_prev').hide('slow');
}