/* ########################################################################### *
/* ***** DOCUMENT INFO ******************************************************* *
/* ########################################################################### *
 * ##### NAME:  global.js
 * ##### VERSION: v1.5
 * ##### UPDATED: 21/02/08 (Mick Chmielewski, Eclipse)
/* ########################################################################### *

/* ########################################################################### *
/* ***** INDEX *************************************************************** *
/* ########################################################################### *
/* ##### INITIALISATION
/* ##### CLEAR FIELD HINT
/* ##### TOP NAVIGATION
/* ##### SEARCH DOMAIN DROPDOWN
/* ##### PAGE OPTIONS
/* ##### CAPTIONED IMAGE
/* ##### PRODUCT SECTIONS
/* ##### FAQ QUESTIONS
/* ##### SITEMAP
/* ##### TAGS LIST
/* ##### POPUP WINDOW
/* ########################################################################### */



/* ########################################################################### *
/* ##### INITIALISATION
/* ########################################################################### */
$(document).ready(init);

function init()
{
	init_pageOptions();
	init_clearHint();
	init_tagDisplay();
	init_dropDownNav();
	init_searchDropDown();
	init_productSections();
	init_faqQuestions();
	init_captionedImage();
	init_sitemapDropDown();
}



/* ########################################################################### *
/* ##### CLEAR FIELD HINT
/* ########################################################################### */
function init_clearHint()
{
	$(".clearHint").focus(function(){
		$(this).attr("value","");
	});
}



/* ########################################################################### *
/* ##### TOP NAVIGATION
/* ########################################################################### */
function init_dropDownNav()
{
	$("ul.gloNav").superfish();
	$("ul.gloNav > li > a").addClass("dropDown");
	$("ul.topNav")
	.superfish()
	.find(">li:has(ul)")
		.mouseover(function(){
			$("ul", this).bgIframe({opacity:false});
		})
		.find("a")
			.focus(function(){
				$("ul", $("ul.topNav>li:has(ul)")).bgIframe({opacity:false});
			});
}



/* ########################################################################### *
/* ##### SEARCH DOMAIN DROPDOWN
/* ########################################################################### */
function init_searchDropDown()
{
	$('#searchList li').sfHover();
	$('.domTel').click(function() {
		$('#searchDomain').removeClass("web");
		if ($('.siteSearch').val() == 'Search Telstra' || $('.siteSearch').val() == 'Search The Web' || $('.siteSearch').val() == '')
		{
			$('.siteSearch').attr({value:"Search Telstra"});
		}
		$('#searchList li').removeClass("sfHover");
	});
	$('.domWeb').click(function() {
		$('#searchDomain').addClass("web");
		if ($('.siteSearch').val() == 'Search Telstra' || $('.siteSearch').val() == 'Search The Web' || $('.siteSearch').val() == '')
		{
			$('.siteSearch').attr({value:"Search The Web"});
		}
		$('#searchList li').removeClass("sfHover");
	});
	$('.domTel,.domWeb').hover(
		function () {
			$(this).addClass("over");
		},
		function () {
			$(this).removeClass("over");
		}
	);
}



/* ########################################################################### *
/* ##### PAGE OPTIONS
/* ########################################################################### */
function init_pageOptions()
{
	var poList = document.createElement('ul');
	poList.id = 'poContainer';
	var oList1 = document.createElement('li');
	oList1.id = 'poPrint';
	var oLink1 = "<span class='replacement'></span><a href='#' class='printLink'><span class='replacement' title='Print this page'></span>Print this page</a>"
	oList1.innerHTML = oLink1;
	var oList2 = document.createElement('li');
	oList2.id = 'poEmail';
	var oLink2 = "<span class='replacement'></span><a href='#' class='bmSend'><span class='replacement' title='Email page'></span>Email page</a>"
	oList2.innerHTML = oLink2;
	$(poList).append(oList1,oList2);
	$('#bdPageOptions').append(poList);
	
	$('.printLink').click(function() {
		// Inserted Omniture Exit link for Print function
		var s=s_gi(s_account);
		s.linkTrackVars='eVar39,events';
		s.linkTrackEvents='event16';
		s.events='event16';
		s.eVar39= 'Print';
		s.prop24=s.eVar39;
		s.tl(this,'o','interaction');
		window.print();
		return false;
	});
}



/* ########################################################################### *
/* ##### CAPTIONED IMAGE
/* ########################################################################### */
function init_captionedImage()
{
	$('.captioned').hover(function(){
		$(this).children('.imgCaption').animate({marginTop: -10, paddingTop: 20}, "normal");
	},function(){
		$(this).children('.imgCaption').animate({marginTop: 0, paddingTop: 10}, "normal");
	});
	$('.captioned').click(function(){
		$(this).next().click();
	});
}



/* ########################################################################### *
/* ##### PRODUCT SECTIONS
/* ########################################################################### */
var DEMO_FLASH = "<div id='flashDemoPlaceholderWrapper'><div id='flashDemoPlaceholder'></div></div>";

function init_productSections()
{
	$('.prodDetails').hide();
	$('.prodSubHead').addClass('expand');
	$('.prodSubHead:first').addClass('open');
	$('.prodSubHead:first').next('.prodDetails').show();
	
	// Find the H2.prodSubHead and give them the generic event handler.
	$('h2.prodSubHead').click(genericProdSubHead_Click);	
		
	// Find the H2 with a .prodDetails next, containing a .demo inside it.
	$('.prodSubHead').next('.prodDetails').find('.demoLink').each(function(){
		// We step up to the prodSection, then look for the first H2:
		var prodSectionH2 = $(this).parent().parent().parent().find('h2.prodSubHead')[0];
		
		// Remove the generic event handler, and attach the specific event handler.
 		$(prodSectionH2).unbind('click', genericProdSubHead_Click);
		$(prodSectionH2).click(demoProdSubHead_Click);
	});
}

function genericProdSubHead_Click ()
{
	//alert($(this)[0].innerHTML);
	if ($(this).hasClass('open')) {
		$(this).next('.prodDetails').hide();
		$(this).removeClass('open');
	}
	else {
		// Remove any playing demos
		$('#flashDemoPlaceholderWrapper').remove();
		// Remove any playing videos
		$('#flashVideoPlaceholderWrapper').remove();
		$('.mediaList li').removeClass('on');
		// Hide any open sections
		$('.prodDetails').hide();
		$('.prodSubHead').removeClass('open');
		// Show the clicked section
		$(this).next('.prodDetails').slideDown();
		$(this).addClass('open');
	}
}

function demoProdSubHead_Click ()
{
	if ($(this).hasClass('open')) {
		// Remove any playing demos
		$('#flashDemoPlaceholderWrapper').remove();
		// Remove any playing videos
		$('#flashVideoPlaceholderWrapper').remove();
		$('.mediaList li').removeClass('on');
		// Show the clicked section
		$(this).next('.prodDetails').hide();
		$(this).removeClass('open');
	}
	else {
		// Remove any playing demos
		$('#flashDemoPlaceholderWrapper').remove();
		// Remove any playing videos
		$('#flashVideoPlaceholderWrapper').remove();
		$('.mediaList li').removeClass('on');
		// Hide any open sections
		$('.prodDetails').hide();
		$('.prodSubHead').removeClass('open');
		//movieWidth = $(this).next('.prodDetails').width();
		demoUrlArray = $(this).next('.prodDetails').find('.demoLink').attr("href");
		$(this).next('.prodDetails').append(DEMO_FLASH);
		$('#flashDemoPlaceholderWrapper').show();
		
		// A collection of links contained in prodDetails that end in swf
		var countSWF = $(this).next('.prodDetails').find('a[href$=swf]').length;
		var hasSWFLink = countSWF > 0;
		// A collection of links contained in prodDetails that end in flv
		var countFLV = $(this).next('.prodDetails').find('a[href$=flv]').length;
		var hasFLVLink = countFLV > 0;
		
		if (hasSWFLink) {
			// Inserted Omniture code to track the playing of Adobe Shockwave demonstration
			var s=s_gi(s_account);
			s.linkTrackVars='eVar39,events,prop24,eVar36,prop25';
			s.linkTrackEvents='event12';
			s.events='event12';
			s.eVar39='Play Media';
			s.prop24='Play Media';
			s.eVar36=demoUrlArray;
			s.prop25=demoUrlArray;
			s.tl(this,'o','interaction');
			//alert('found a swf link');
			$('#flashDemoPlaceholder').flash({
					src: demoUrlArray,
					width: 450,
					version: 8
				}
			);
		}
		else if (hasFLVLink) {
		    // Inserted Omniture code to track the playing of video demonstration
			var s=s_gi(s_account);
			s.linkTrackVars='eVar39,events,prop24,eVar36,prop25';
			s.linkTrackEvents='event12';
			s.events='event12';
			s.eVar39='Play Media';
			s.prop24='Play Media';
			s.eVar36=demoUrlArray;
			s.prop25=demoUrlArray;
			s.tl(this,'o','interaction');
			// Define the width and height of the movie.
			var WIDTH_RATIO = 0.5625;
			movieWidth = 450;
			movieHeight = Math.round(WIDTH_RATIO*movieWidth);
			//alert('found a flv link');
			$('#flashDemoPlaceholder').flash({
					src: '/Style%20Library/teg/flash/videoPlayer.swf',
					width: movieWidth,
					height: movieHeight,
					allowFullScreen: "true",
					version: 8,
					flashvars: {
						displayWidth: movieWidth,
						displayHeight: movieHeight,
						videoFile: demoUrlArray				    
					}
				}
			);
		}
		
		
		$(this).next('.prodDetails').find('.demoLink').parent().hide();
		$(this).next('.prodDetails').show();
		$(this).addClass('open');
	}
}



/* ########################################################################### *
/* ##### FAQ QUESTIONS
/* ########################################################################### */
function init_faqQuestions()
{
	$('.answer').hide();
	$('.faqList li').addClass('expand');
	
	$('.faqList h2').click(function(){
		if ($(this).parent().hasClass('on')) {
			$(this).next('.answer').slideUp();
			$(this).parent().removeClass('on');
		}
		else {
			$('.answer').slideUp();
			$('.answer').parent().removeClass('on');
			$(this).next('.answer').slideDown();
			$(this).parent().addClass('on');
		}
	});
}



/* ########################################################################### *
/* ##### SITEMAP
/* ########################################################################### */
function init_sitemapDropDown()
{
	$('a.sm_toggle,a.sm_close').click(function() {
		$('.ftSitemap').slideToggle("slow");
		return false;
	});
}



/* ########################################################################### *
/* ##### TAGS LIST
/* ########################################################################### */
function init_tagDisplay()
{
	//Change fifth item comma to elipses and hide the rest of the tags
	$(".tags").each(function(){
		midTag = $(this).contents(":nth-child(6)").html();
		if (midTag) {
			newMidTag = midTag.replace(",","...");
			$(this).contents("dd:nth-child(6)").html(newMidTag);
			$(this).contents("dd:nth-child(6)").nextAll().hide();
		}
	});
		
	//Display hidden tags on rollover
	$(".tags").hover(function(){
		midTag = $(this).contents(":nth-child(6)").html();
		if (midTag) {
			newMidTag = midTag.replace("...",",");
			$(this).contents("dd:nth-child(6)").html(newMidTag);
			$(this).contents("dd:nth-child(6)").nextAll().show();
		}
	},function(){
		midTag = $(this).contents(":nth-child(6)").html();
		if (midTag) {
			newMidTag = midTag.replace(",","...");
			$(this).contents("dd:nth-child(6)").html(newMidTag);
			$(this).contents("dd:nth-child(6)").nextAll().hide();
		}
	});
}



/* ########################################################################### *
/* ##### POPUP WINDOW
/* ########################################################################### */

function popWindow(linkUrl) {
	targetHref = $(linkUrl)[0].href;
	window.open(targetHref,"_blank","height=640,width=700,toolbar=no,menubar=no,location=no,scrollbars=yes,status=no");
	// Return false to prevent the link click navigation occuring.
	return false;
}
