/*****************************************************************************************
 *	Site specific javascript
****************************************************************************************/

var fostersgroup = window.fostersgroup || {};

fostersgroup = (function() {
	
	var loc = location.href;
	var BASE_URL = '';	
	if(loc.indexOf('fostersgroup.dev.areeba.com.au') == -1) {
		BASE_URL = 'http://careers.fosters.com.au';
	/*
		if((loc.indexOf('http://uat.pageuppeople') <= 0) && (loc.indexOf('searchjobs.fosters') <= 0)) {
			var BASE_URL = 'http://careers.fosters.com.au';
		} else {
			var BASE_URL = '';
		}
	*/
	}
	
	var initFlash = function() {
		
		if ((typeof BASE_URL == 'undefined') || (typeof isRedDot != 'undefined')) return;
		if ((typeof isRedDotPreview != 'undefined')) return;

				
		$('body.home-page #banner h1, body.home-page #banner h2, body.home-page div.block h2').flashText({
			src: BASE_URL + '/Common/flash/swfs/TheSansB3Light_Regular.swf'
		});
		
		$('#main-inner h1').flashText({
			src: BASE_URL + '/Common/flash/swfs/TheSansB3Light_Regular.swf'
		});
		$('div.product-wrapper div.productcontent h2').flashText({
			src: BASE_URL + '/Common/flash/swfs/TheSansB3Light_Regular.swf'
		});

	};
	
	var addNavClasses = function() {
		$('#primary-navigation ul li:last-child').addClass('last');
		$('#primary-navigation ul ul').bgiframe();
	};
		
	var helperHover = function(el){
		 $(el).hover(
			function() { $(this).addClass('arb-hover ui-state-hover'); },
			function() { $(this).removeClass('arb-hover ui-state-hover'); }
		);
		 
	 };

	var pageControls = function(){
		arb.functions.fontSizing('#page-controls-box', {
			controlsFontSize:12,
			insertHTML: '<ul id="page-controls" class="clearfix"><li id="font-size-down-control" class="image-replaced" title="Decrease font size">A-<span></span></li><li id="font-size-up-control" class="image-replaced" title="Increase font size">A+<span></span></li><li class="print-link"><a href="#" title="Print page">Print Page</a></li></ul>'
		});
	};
	
	var searchableSelects = function(el){
		var $thisClass = $(el).attr('class');
		
		$(el).each(function()
		{
			var $thisClass = $(this).attr('class');
			/* Hide list element */
			$(this).css("display", "none");		
			/* Create new ID for the select, use existent Id of UL but add the _Select prefix */
			var ElId = $(this).attr("id") + "_Select";
			/* Create new Select-element */
			$(this).after("<select id='" + ElId + "' class='" + $thisClass + "'></select>");
			/* Loop-through list and add children to select */
			$(this).find("li").each(function()
			{
			/* Setup values */
			var Anchor = $(this).find("a").eq(0), Value = (Anchor.length > 0 ? $(Anchor).attr("href") : '');
			var SelectedElement = ($(this).hasClass("selectedItem") ? ' selected' : '');
			/* Add child to select */
			$("#"+ElId).append("<option value='"+Value+"'"+SelectedElement+">"+$(this).html()+"</option>");
			});
		});
		/* Hook selects */
		$("select." + $thisClass).change(function()
		{
			if(this.value.length > 0) window.location.href = this.value;
		});
	};
	
	
	var hideSearchTips = function() {
		$('#search-tips').hide();
		$('#toggle-search-tips').click(function () {
			$('#search-tips').toggle("slow");
			return false;
		});
	};
	
	/* To add rollovers and click states to <img> and <input type="image"> tags */
	var imageHelper = function(){
		$('#newsletter-subscribe input.button').imageHelper();
		$('#search-form input.button').imageHelper();
		$('#search-block-top input.searchbutton').imageHelper();
	};

	return  { // Everything that is returned in this object literal will be public
		
		init: function() {
			initSlideShow();
			pageControls();
			addNavClasses();
			hideSearchTips();
			helperHover('div.button a');
			$('div.category-download ul:first').addClass('first');
			arb.functions.linkButtons('div.buttons-form-item input');
			imageHelper();
			initFlash();
		}
		
	};

})(); // Invoke the function creating a closure and assign the returned object literal



/**
 * Let's get it started
 */
$(document).ready(function() {
	fostersgroup.init();
});