﻿// MEDWAY JAVASCRIPT FILE

jQuery.fn.exists = function () { return jQuery(this).length > 0; }

// FLASH OR HTML MENU
function flashOrHTMLMenu()
{
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
	{
		document.getElementById('flashMenu').style.display='block';
		document.getElementById('HTMLMenu').style.display='none';
	}
	else 
	{
		document.getElementById('flashMenu').style.display='none';
		document.getElementById('HTMLMenu').style.display='block';
	}
}

function tradeDoubler()
{
     var uri = 'http://impgb.tradedoubler.com/imp?type(js)g(16186808)a(1674645)' + new String (Math.random()).substring (2, 11);
     document.write('<script type="text/javascript" src="'+uri+'" charset="ISO-8859-1"> </script>');
 }

 function equalHeight(group) {
     tallest = 0;
     group.each(function() {
         thisHeight = $(this).height();
         if (thisHeight > tallest) {
             tallest = thisHeight;
         }
     });
     group.height(tallest);
 }

/*Tab controller
 $(function() {
     var tabContainers = $('div.tabs > div');
     tabContainers.hide().filter(':first').show();

     $('div.tabs ul.tabNavigation a').click(function() {
         tabContainers.hide();
         tabContainers.filter(this.hash).show();
         $('div.tabs ul.tabNavigation a').removeClass('selected');
         $(this).addClass('selected');
         return false;
     }).filter(':first').click();
 });*/

 /**
  * Tab controller
  */
 function tabController() {
	// Get some variables
	var tabContainers = $('div.tabs > div');
	var tabNavigation = $('div.tabs ul.tabNavigation a');
	var activeClass = 'selected';
	var suffix = 'Tab'; // Suffix is added to the end of tab IDs

	// Hide all tabs
	tabContainers.hide();

	// Bind tab navigation click event
	tabNavigation.click(function (e) {
		var hash = this.hash;
		tabContainers.hide().filter(hash).show();
		tabNavigation.removeClass(activeClass).filter('[href="' + hash + '"]').addClass(activeClass);
		location.hash = hash.substr(0, hash.length - suffix.length);
		e.preventDefault();
	});

	// Select a tab if specified in the URL, or select the first by default
	var hash = location.hash + suffix;
	var tab = tabNavigation.filter('[href="' + hash + '"]');
	if (tab.size() > 0) {
		tab.click();
		location.hash = hash; // Forces browser to scroll to this point
		location.hash = hash.substr(0, hash.length - suffix.length); // Replace fragment with nice fragment
	} else {
		tabNavigation.filter(':first').click();
	}
}

$(document).ready(function () {

    if ($(".formSubmissionLoading").exists()) {
        
        redirectToAnotherURLForTheSakeOfA1WebStats();
    }


    $(".lightbox").lightbox();
    equalHeight($(".imageLinkContainer"));


    $('template p:last').css('margin-bottom : 0');

    $('#holidayImageTable .holidayThumbnail ').hover(function () {
        var pickId = $(this).attr('id');
        pickId = pickId.split('_')[1];
        $('.LargeImageHolder').addClass('hidden');
        $('#largeImage_' + pickId).removeClass('hidden');
    })

    // Initialise tabs
    tabController();
});

function redirectToAnotherURLForTheSakeOfA1WebStats() {
    var redirectTimer = setTimeout("window.location = A1StatsRedirectURL;", 3000);
}

 
 
 
