/*==============================================================================
 Global JS
 @author Bruce Thomas
==============================================================================*/

// IE6 background flicker fix - see: http://www.mister-pixel.com/#Content__state=is_that_simple
try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}

// initialize jQuery
jQuery.noConflict();

// on Dom ready
jQuery(function($){

	// higlight current lang
	$('.lang ul li a').each(function() { 
		var lang = Left($(this).children('span').html().toLowerCase(),3); 
		if (lang == language()) { 
			$(this).parent('li').addClass('selected'); return; } 
		});
	
	// highlight active footer nav item
	$('.footer .legals ul li a:path').each(function() { $(this).parents('li').addClass('selected'); });
	
	// highlight active utility nav item
	$('.globalnav a:path').each(function() { $(this).addClass('selected'); });

	// interactive demo
	// display first paragraph
	$('#demo .dot_nav .inner p').each(function() {
		var x = 0;
		$('#demo .dot_nav .inner p').eq(x).show('fast'); 
		$('#demo .dot_nav ul li').eq(x).addClass('selected')
	});

	// arm the links, show text, update image
	$('#demo .dot_nav ul a').click(function(e) {
		e.preventDefault();
		var hash = getHash( this + '' );
		$('#demo #step_image').attr('src', '/images/sample/screen_'+hash+'.jpg');
		$('#demo .dot_nav ul li').eq(hash).addClass('selected').siblings('li').removeClass('selected');
		$('#demo .dot_nav .inner p').eq(hash).show('fast').siblings('p').hide();
	});
	
	// sub-navigation (open active & arm links)
	$('.support ul').each(function(){
		var hash = document.location.toString();
		if( hash.indexOf('#') >0 ) {
			var x = getHash( document.location.toString() + '' );
			//alert('xx' + x);
			$(this).children('li').eq(x).addClass('selected');
		}
	});

	$('.support ul li a').click( function(e) {
		// parnets ...
		e.preventDefault();
		$(this).parent('li').toggleClass('selected').siblings('li').removeClass('selected');
	});

	// sub-navigation redirect links
	$('.support ul li ul li a').click( function(e) {
		// children ...
		document.location.href = this;
	});
	

});



function language () {
	// find the language from the URL
	loc = document.location.toString().split('/')[3];
	return loc;
}

function getHash( strLoc ) {
	// returns the location hash minus the #
	var tmp = String(strLoc).split('#');
	return parseInt(tmp[1]);
}

function script_name() {
	// just the script name!!!!
	var l = document.location.href.split('/');
	var i = l.length;
	return l[i-1];
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function iif( condition, val1, val2 ) {
	if (condition) return val1; return val2;
}

function getElem( strLayerID ) {
	// returns the style element
	var whichLayer = strLayerID;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	return elem;
}

