﻿function InitDefault() {

	// call other Init functions
	InitNav();

	DoStriping();

	// helpers for style
	$('.two-col-listing li:odd').addClass('no-right-margin');


}

function InitGrid() {
	$('html').keyup(function(event) {
		if (event.keyCode == 27) {
			($('body').hasClass('grid')) ? $('body').removeClass('grid') : $('body').addClass('grid');
		}
	});
}

function InitNav() {
	$('#main-nav li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
		$(this).children('ul').css('left', -9999);
		$(this).children('ul').css('opacity', 1);
	});
}

function InitExpand() {
	$('#hidden-tags').hide();
	$('#expand-tag-listing').toggle(
		function() {
			$('#hidden-tags').slideDown();
			$('#expand-tag-listing').text("Contract list")
			$('#expand-tag-listing').addClass('up');
		}, function() {
			$('#hidden-tags').slideUp();
			$('#expand-tag-listing').text("Expand list")
			$('#expand-tag-listing').removeClass('up');
		}
	)
}


function eProspectusInitExpand() {
    $('#hidden-panel').hide();
    $('#expand-adv-search').toggle(
		function() {
            $('#hidden-panel').slideDown();
		    $('#expand-adv-search').text("Hide advanced search")
		    $('#expand-adv-search').addClass('up');
		}, function() {
		    $('#hidden-panel').slideUp();
		    $('#expand-adv-search').text("Show advanced search")
		    $('#expand-adv-search').removeClass('up');
		}
	)
}


function SetEnterSubmit() {
	// usage: add the class 'submit-on-enter' to any element
	$(".submit-on-enter input[type=text], .submit-on-enter textarea").keydown(function(ev) {
		//$(".submit-on-enter").append(ev.keyCode);
		if (ev.keyCode == 13) {
			ev.preventDefault();
			ev.stopPropagation();
			//$(".submit-on-enter").append("==submitting");    
			$(this).parents(".submit-on-enter").children("input[type=image], input[type=button]").click();
			return false;
		}
	});
}

function SetExternalLinks() {
	/*
	Purpose: checks all <a>'s in the doc, if it has a rel attribute of 'external', sets to open in new window
	usage: <a href="http://www.google.com" rel="external">Google</a>
	*/

	$('a[rel=external]').click(function() { window.open(this.href); return false; });

}

function Equalise(elms) {
	/*
	Purpose: simple EQ for columns / pods / etc
	usage: Equalise($(".eq-what";
	*/
	var highest = 0;
	for (i = 0; i < elms.length; i++) { if ($(elms[i]).height() > highest) highest = $(elms[i]).height(); }
	for (i = 0; i < elms.length; i++) { if ($(elms[i]).height() < highest) $(elms[i]).height(highest); }
}

function DoStriping() {
	$('table > tbody > tr:even').addClass("alt");
}

jQuery.fn.setEqualHeight = function(o) {
    var maxHeight = 0;
    $(this).each(function(i) {
        var thisHeight = $(this).height();
        if (thisHeight > maxHeight) {
            maxHeight = thisHeight;           
        }        
    });        
    $(this).height(maxHeight);
}

function InitGateway() {

   	$(".gateway-panel-header a").setEqualHeight();
   	$(".gateway-panel-header1 a").setEqualHeight();
   	$(".gateway-panel-header2 a").setEqualHeight();
   	$(".gateway-panel-header3 a").setEqualHeight();

   	$(".four-col-pods li").setEqualHeight();
   	$(".three-col-pods li").setEqualHeight();   	 
}

function InitHomepage() {
	$('#home-tabs li a').click(function() {
		$('#home-tabs li').removeClass('selected')
		$(this).parent().addClass('selected')
		$('#home-tabs').attr('class', '');
		$('#home-tabs').addClass($(this).parent().attr('id'));
		$('#home-tabs').addClass('self-clear');

		//$('#homepage-feature .section').fadeOut();
		$('#homepage-feature .section').hide();
		
		var toShow = '#' + $(this).parent().attr('id') + '-data';
		//$(toShow).stop().fadeIn();
		$(toShow).stop().show();
		
		return false;
	});

	$('#proptabs li a').click(function() {
		$('#proptabs li').removeClass('selected')
		$(this).parent().addClass('selected')
		$('#proptabs').attr('class', '');
		$('#proptabs').addClass($(this).parent().attr('id'));
		$('#proptabs').addClass('self-clear');

		//$('#homepage-feature .section').fadeOut();
		$('#who-what-how .section').hide();

		var toShow = '#' + $(this).parent().attr('id') + '-section';
		//$(toShow).stop().fadeIn();
		$(toShow).stop().show();

		return false;
	});
    
	$('.rotating-features ul').cycle({
	    fx: 'fade',
	    timeout: 7000,
	    delay: 2000,
	    pause: 'true'
	});


	$('.home-rotating-features ul').cycle({
	    fx: 'fade',
	    timeout: 7000,
	    delay: 2000,
	    pause: 'true'
	});


	$(".homepage-bottom-column div.hcEqual").setEqualHeight();
	$(".home-rotating-features").setEqualHeight();

	
}


