/* 
 * general function
 */
$(document).ready(function() {
	$('#contactform input, #contactform textarea, #contactform input[type="checkbox"], #contactform select, #contactform input[type="radio"], #contactform input[type="file"]').uniform();
	$('#curr_con input, #curr_con select').uniform();
	$('#contactform').validate();
	$('.datepicker').datepicker({ dateFormat: 'dd/mm/yy' });
	$('#weather').weatherfeed(['BKXX0004']);
	$('#flash360').flash(
		{
			swf: APP_URL+'swf/360.swf',
			height: 618,
			width: 875,
			encodeParams: false,
			allowFullScreen: true,
			allowScriptAccess: true,
			allowNetworking: true,
			menu: false,
			wmode: 'transparent',
			flashvars: {
				lwImg: "resources/apartman_360_logo.gif",
				lwBgColor: "255,0,0,0",
				lwBarBgColor: "255,241,88,41", 
				lwBarColor: "255,241,88,41", 
				lwBarBounds: "190,438,500,2", 
				lwlocation: "0", 
				lwShowLoadingPercent: "true", 
				lwTextColor: "255,241,88,41", 
				iniFile: "config_apartman.bin", 
				progressType: "0", 
				swfFile: "", 
				href: location.href			 
			}
		}
	);
	
	//MENU FOR MOBILE
	$('#mobile_menu').click(function(){
		$('.navigation').toggle('slow');
	})
	
	if ($("a[rel^='prettyPhoto']").length > 0)
	$("a[rel^='prettyPhoto']").prettyPhoto();
	// vieos
	
	$(".fancyboxlink").fancybox({
		'padding' : 0,
		'autoScale' : false,
		'transitionIn' : 'none',
		'transitionOut' : 'none'/*,
		'type'				: 'swf',
		'width'				: 500,
		'height'			: 500,*/
		
	});
	
	$(".fancyboximage").fancybox({
		'padding' : 0,
		'autoScale' : false,
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'type'				: 'swf',
		'width'				: 400,
		'height'			: 300
	});
	
	//Caption Sliding (Partially Hidden to Visible)
	var img_height = 0, div_height = 0, h3_height = 0;
	$('.boxgrid.caption').hover(function(){
		
		img_height = $(this).find('img').height();
		div_height = $(this).find('div').height();
		h3_height = $(this).find('h3').height();
		var paragraph_height = ($(this).find('img').height() - ($(this).find('div').height()));
		$(".cover", this).stop().animate({top:paragraph_height+"px"},{queue:false,duration:160});
	}, function() {
		//console.log(img_height ,  div_height, h3_height);
		$(".cover", this).stop().animate({top:(img_height -  h3_height- 5)+"px"},{queue:false,duration:160});
	});
	
	if ($('#galleria').length){
		// Load the classic theme
		Galleria.loadTheme(APP_URL+'css/galleria.classic.min.js');
		
		$('#galleria').galleria({
		imageCrop: true
		
		});
		
	}
	//set navigation for non mobile version
	$(window).resize(function() {
		if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
			
		}
		else{
			if ($(window).width() > 633) {
				$('.navigation').css('display','block');
			}
			else{ 
				$('.navigation').css('display','none');
			}
		}
		$(".cover").stop().animate({top:($('.caption').children('img').height() - $('.boxgrid.caption').find('h3').height() - 5)+"px"},{queue:false,duration:160});
		
		if ($('#galleria').length)
			Galleria.get(0).exitFullscreen();
	});
	
	//location link - images 
	var default_image = $(".location_img").attr('id');
	$(".location").hover(function(event){
		//$(".location_img").stop().attr("backgroundImage",$(this).attr('src')).fadeTo("slow", 1.0);
		if($.browser.msie && $.browser.version=="6.0") {
				var new_url = $(this).attr('id').replace(".png", ".jpg");
				$(".location_img").stop().css("backgroundImage" , 'url('+new_url+')').fadeTo("slow", 1.0);
		}
		else
		$(".location_img").stop().css("backgroundImage" , 'url('+$(this).attr('id')+')').fadeTo("slow", 1.0);
		$(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
		
	},function(event){
		//$(".main_location img").stop().attr("src",default_image).fadeTo("slow", 1.0);
		if($.browser.msie && $.browser.version=="6.0") {
				var new_url = default_image.replace(".png", ".jpg");
				$(".location_img").stop().css("backgroundImage" , 'url('+new_url+')').fadeTo("slow", 1.0);
		}
		else
		$(".location_img").stop().css("backgroundImage" , 'url('+default_image+')').fadeTo("slow", 1.0);
		$(this).fadeTo("slow", 0.6); // This should set the opacity back to 30% on mouseout
	});
	
	$(".tt").hover(function(event){
		if($.browser.msie && $.browser.version=="6.0") {
			 $('#obj_type_of_room').hide();	
		}
		
	},function(event){
		if($.browser.msie && $.browser.version=="6.0") {
			 $('#obj_type_of_room').show();	
		}
	});
	
	$('#convert').click(function(){
	 
	 //Get all the values
	 var amount = $('#amount').val();
	 var from = $('#fromCurrency').val();
	 var to = $('#toCurrency').val();
	 
	 //Make data string
	 var dataString = "amount=" + amount + "&from=" + from + "&to=" + to;
	 
		 $.ajax({
		   type: "POST",
		   url: APP_URL+"ajax_converter.php",
		   data: dataString,
		   success: function(data){
			 //Show results div
			$('#results').show();
			
			if($.browser.msie && $.browser.version=="6.0") $('#results').css('display', 'inline');
			
			//Put received response into result div
			if (isNumber($('#amount').val())) {
				var from = $('#fromCurrency option:selected').text().split(' - ');
			var to = $('#toCurrency option:selected').text().split(' - ');
			var result = $('#amount').val() + " " + from[0] + " = " + (data * $('#amount').val())+ " " + to[0];
			}
			else var result = "Can't process the conversion";
			
			$('#results').html(result);
		   }
		 });
	});
});
$(window).load(function () {
	$(".location").fadeTo("slow", 0.6);
	$(".cover").stop().animate({top:($('.caption').children('img').height() - $('.boxgrid.caption').find('h3').height() - 5)+"px"},{queue:false,duration:160});
	
	
});
function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}


