$(function(){
	//Menu Code
	$("#sideMenu").each(function(){
		$("li",this).hover(function(){ 
			$(">ul", this).fadeIn("fast"); 
		}, function(){
			$(">ul", this).fadeOut("fast"); 
		});
	});
	
	$("#property .photos").unbind().mousemove(function(e){
		var p = ($("span",this).width()-$(this).width()) / 100;
		if(p>0){
			var c = ((e.pageX - $(this).offset().left) / $(this).width())*100;
			$("span",this).stop().animate({"left":"-" + (p * c) + "px"},"slow","easeOutExpo");
		}
		var p = ($("span",this).height()-$(this).height()) / 100;
		if(p>0){
			var c = ((e.pageY - $(this).offset().top) / $(this).height())*100;
			$("span",this).stop().animate({"top":"-" + (p * c) + "px"},"slow","easeOutExpo");
		}
	}).mouseout(function(e){
		$("span",this).stop().animate({"left":"0px"},"slow","easeOutExpo");
		$("span",this).stop().animate({"top":"0px"},"slow","easeOutExpo");
	}).each(function(){
		$("a",this).lightBox();
		
	});
	
	$(".propType").change(function(e){
		if($(this).val()!=""){
			window.location = $(this).val();
		}
	});
	
	$("#search select.auto").change(function(e){
			$("#search form").submit();
	});
	
	
	//Map Code!
	var map = ".map";
	var address = $('.address').html() + " " + $('.address').attr("postcode");
	$(map).each(function(){
		if(point = $(map).attr("point")){
			point = point.split(",");
	   		placeMarkMap(map,address,[point[0],point[1]]);
		}
		else{
			//Get the address
			$("<div></div>").jmap('init', {
				'mapType':'map',
				"mapZoom":16,
				'mapShowjMapsIcon': false,
				'mapEnableType': true
			}).jmap('SearchAddress', {
		        'query': address,
		        'returnType': 'getLocations'
		    }, function(result, options){
		        var valid = Mapifies.SearchCode(result.Status.code);
		        if (valid.success) {
		       		$.each(result.Placemark, function(i, point){
		           		placeMarkMap(map,address,[point.Point.coordinates[1], point.Point.coordinates[0]]);
		                return false;
		            });
		        }
		    });
		}
	});
});

function placeMarkMap(map,address,p){
	$(map).jmap('init', {
		'mapType':'map',
		"mapZoom":16,
		'mapShowjMapsIcon': false,
		'mapEnableType': true,
		'mapCenter':p
	}).jmap('AddMarker',{
        'pointLatLng':p,
        'pointHTML':address,
		'centerMap': true
    });
}

