//google.setOnLoadCallback(function() {
$(function(){	

	$('#offer-a').click(function(){
		$('#form-introductory').css("background-image","url(../assets/images/form-introductory.png)");
		$('.button').css("bottom","330px");
	});
	
	$('#offer-b').click(function(){
		$('#form-introductory').css("background-image","url(../assets/images/form-introductory-b.png)");
		$('.button').css("bottom","330px"); 
	});

	$('#offer-c').click(function(){
		$('#form-introductory').css("background-image","url(../assets/images/form-introductory-c.png)");
		$('.button').css("bottom","245px");
	});
	
	$('#offer-d').click(function(){
		$('#form-introductory').css("background-image","url(../assets/images/form-introductory-d.png)");
		$('.button').css("bottom","330px");
	});
	
	$('#offer-e').click(function(){
		$('#form-introductory').css("background-image","url(../assets/images/form-introductory-e.png)");
		$('.button').css("bottom","237px"); 
	});
	
	var s1 = $("#route-1-step-1");
	var s2 = $("#route-1-step-2");
	var s3 = $("#route-1-step-3");
	var s4 = $("#route-1-step-4");
	
   	s2.hide();
	s3.hide();
	s4.hide();

	s1.find('.button').click(function(){
		s1.hide();
		s2.fadeIn('slow');
	});
	
	s2.find('.button').click(function(){
		s2.hide();
		s3.fadeIn('slow');
	});
	
	s3.find('.button').click(function(){
		s3.hide();
		s4.fadeIn('slow');
	});
	
	s4.find('.button').click(function(){
		disablePopup();		
		$("#article").css("background-image","url(../assets/images/article-full.png)");
		$(".button").hide();
	});
	
	//SETTING UP OUR POPUP
	//0 means disabled; 1 means enabled;
	var popupStatus = 0;
	var overlay = $("#overlay");
	var popup = $("#popup");

	//loading popup with jQuery magic!
	function loadPopup(){
		//loads popup only if it is disabled
		if(popupStatus==0){
			overlay.css({
				"opacity": "0.7"
			});
			overlay.fadeIn("slow");
			popup.fadeIn("slow");
			popupStatus = 1;
		}
	}

	//disabling popup with jQuery magic!
	function disablePopup(){
		//disables popup only if it is enabled
		if(popupStatus==1){
			overlay.fadeOut("slow");
			popup.fadeOut("slow");
			popupStatus = 0;
		}
	}

	//centering popup
	function centerPopup(){
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = popup.height();
		var popupWidth = popup.width();
		//centering
		popup.css({
			"position": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6

		overlay.css({
			"height": windowHeight
		});
	}

	$("#open").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	$("#close").click(function(){
		disablePopup();
	});
	
	overlay.click(function(){
		disablePopup();
	});
	
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	$('.carousel a').each(function(){
		$(this).hover(function() {		
			$(this).find("img").attr("src", $(this).find("img").attr("src").replace(/off/, "on"));
		}, function() {
			$(this).find("img").attr("src", $(this).find("img").attr("src").replace(/on/, "off"));
		});	
	});
	
	//open links in new window
	$('a[rel*=external]').attr("title","This link will open in a new window").click(function(e){
		window.open(this.href);
		e.preventDefault();
	});
	
	//smooth page scrolling
    $('a.scroll[href*=#]').click(function() {
    	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        	&& location.hostname == this.hostname) {
        	var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
    });
	
});