﻿<!-- Function that supports the current pagination model -->
function GoToPage( pageNumber, formNumber )
{
	//Update the form field
	var iPageNumber = document.getElementById('pagination_number_' + formNumber );
	
	//Set value
	iPageNumber.value  = pageNumber;
	
	//Get form
	var oForm = document.getElementById('pagination_select_form_' + formNumber );
	
	//Submit
	oForm.submit();
}	


var contact = {
    allCountries: null,
    activeCountry: null,
    countryTitle: null,

    init:function(){
		
        if($(".contact_data, #newsletter").length == 0) return;
		
        // finds all countries in selectbox (links with classnames) and init events
        contact.allCountries = $("#countries li").find("a");
        $(contact.allCountries).each(function(){
            $(this).click(function(ev){
                contact.activeCountry = $(this).attr('class');
                contact.activateCountry();
				$('#maps_address').val($(this).attr('location'));
				$('#maps_language').val($(this).attr('language'));
                ev.preventDefault();
            });
        });

        $(".contact_map_overlay a").each(function(){
            $(this).click(function(ev){
                contact.activeCountry = $(this).attr('class');
				$('#maps_address').val($(this).attr('location'));
				$('#maps_language').val($(this).attr('language'));
                contact.activateCountry();
                ev.preventDefault();
            });
        });

		$('#get_directions_form').submit(function(ev) {
			window.open(
				'http://maps.google.' + $('#maps_language').val() + '/?q='
					+ 'from:' + $('#directions_input').val()
					+ ' to:'  + $('#maps_address').val()
			);
			ev.preventDefault();
		});

        // first time there is no country selected, so we need to find the first one and activate it
        if(contact.activeCountry == null){
            contact.activeCountry = $(contact.allCountries[0]).attr('class');
            contact.activateCountry();
        }
    },
    activateCountry:function(){
       contact.showCountryData();
       contact.showCountryLabel();
       contact.setSelectboxText();
    },
    showCountryData: function(){
        $(".countries_data p").css('display', 'none');
        $(".countries_data p."+contact.activeCountry).css('display', 'block');
    },
    showCountryLabel: function(){
        $(".contact_map_overlay a img").hide();
        $(".contact_map_overlay a."+contact.activeCountry+" img").fadeIn('medium');
    },
    setSelectboxText: function(){
        $(".select span.text").html("");
        $(".select span.text").append($("#countries li a."+contact.activeCountry).html());
    }
}

$(document).ready(function(){
	contact.init();
});
