/* Author: 

*/

51.51387, -0.14677


var map;
 
function initialize() {
	// Load Map
	map = new google.maps.Map(document.getElementById('google-map'), {
		zoom: 15,
		center: new google.maps.LatLng(51.51387, -0.14677),
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		mapTypeControl: false,
		scaleControl: true,
		streetViewControl: false
	});
 
	// Add Marker
	marker = new google.maps.Marker({
		position: new google.maps.LatLng(51.51387, -0.14677),
		map: map,
		icon: 'img/map-icon.png',
		title: 'ristorante semplice'
	});
}
 

  
  
function px2int(s) {
	return parseInt(s.replace("px", ""));
}

jQuery(function($){


	// TRANSITION + FULL SCREEN IMAGE
	if($('html').hasClass('ie6'))
	{
		$("#bg-transition").fullSizeImage({ 
		 overlayLine: true,
		 repositionImage : true,
		 offset : "0,0",
		 position : "absolute"
		});
	}
	else
	{
		$("#bg-transition").fullSizeImage({ 
		 overlayLine: true,
		 repositionImage : true,
		 offset : "0,0",
		 position : "fixed"
		});
	}
	
	$('#bg-transition').rotate({interval: 4500, transition_time: 2000});
	

	
	// GOOGLE MAP - only on Contact page

	if ($("#google-map").size() > 0) {
		google.maps.event.addDomListener(window, 'load', initialize);
	}

	
	
	// SCROLLING

	$(".scroll-down-button, .scroll-up-button").hover(function() {
		$(this).stop().fadeTo(500, 1.0);
	}, function() {
		$(this).stop().fadeTo(500, 0.0);
	});
	
	$(".scroll-down-button").click(function() {
		scroll($(".menus-content"), -1);
	});
	
	$(".scroll-up-button").click(function() {
		scroll($(".menus-content"), 1);
	});
	
	function setScrollbarVisibility(wrapper_object) {
		if ((wrapper_object.height() - wrapper_object.children().height()) >= 0) {
			wrapper_object.parent().children(".scrolling-arrows").hide();
		}
	}
	
	setScrollbarVisibility($(".menus-content"));
	

	function scroll(wrapper_object, dir) {
		var scrolling_object = wrapper_object.children();
		var max_offset = wrapper_object.height() - scrolling_object.height();
		
		var cur_top = px2int(scrolling_object.css("top"));
		var new_top = cur_top + (dir * 200);
		
		if (dir < 0) {
			if (new_top < max_offset) {
				new_top = max_offset;
			}
		} else {
			if (new_top > 0) {
				new_top = 0;
			}
		}
				
		scrolling_object.stop().animate({top: new_top + (dir * 20)}, 200, function() {
			$(this).animate({top: new_top - (dir * 10)}, 100, function() {
				$(this).animate({top: new_top}, 100);
			});
		});
	}
	
	
	
	// REVIEWS - FOOTER
	
	$("footer .reviews-wrapper").cycleTwitter({
		interval: 8000, 
		transition_time: 1500
	});	

	
	// FORM - default value
	
	$(".default-value").focus(function() {
		if ($(this).val() == $(this).attr("title")) {
			$(this).val("");
		}
	})
	
	$(".default-value").blur(function() {
		if ($(this).val().length == 0) {
			$(this).val($(this).attr("title"));
		}
	})
	
	
	
	// GALLERY
	
	$(".gallery-open").click(function() {
		if ($(this).parent().children("ul.gallery").is(":visible")) {
			$(this).parent().children("ul.gallery").slideUp(500);
			$(this).parent().removeClass("visible");
		} else {
			$("ul.gallery:visible").slideUp(500);
			$("ul.gallery:visible").parent().removeClass("visible");
			$(this).parent().children("ul.gallery").slideDown(500);
			$(this).parent().addClass("visible");
		}
	});

  // FOOTER FORM DROPDOWN STYLING
  
  $('select.select').each(function(){     
    var title = $(this).children('option:selected').html();
  
    $(this).css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
      .after('<span class="select">' + title + '</span>')
      .change(function(){
        val = $('option:selected',this).text();
        $(this).next().text(val);
      });
  });
	
})
