if(!window.ND){window.ND={};window.NextDigital=window.ND;}
/* 2008/01/10 - ND.addLoadListener v0.82 - Glenn Baker */
ND.addLoadListener=function(fn){if(typeof window.addEventListener!='undefined'){window.addEventListener('load',fn,false);}else if(typeof document.addEventListener!='undefined'){document.addEventListener('load',fn,false);}else if(typeof window.attachEvent!='undefined'){ window.attachEvent('onload',fn);}else{var oldfn=window.onload;if(typeof window.onload!='function'){window.onload=fn;}else{window.onload=function(){oldfn();fn();};}}};
/* 2008/01/14 - ND.anchors v0.99 - Glenn Baker - Support for, external, popup:XXX:XXX, close, and print. Includes PopupWindow(url,n,w,h,sc) */
ND.anchors={storage:{external:function(){var ex=window.open(this.href);return !ex;},popup:function(){var dims=arguments&&arguments.length==2?arguments:window.__popupDims;popupWindow(this.href,'name',dims[0],dims[1],'yes');return false;},close:function(){window.close();return false;},print:function(){window.print();return false;}},init:function(){if(this !=ND.anchors){return ND.anchors.init();}window.popupWindow=this.popupWindow;if(!window.__popupDims)window.__popupDims=[619,380];var atype=window.__aType?window.__aType:"rel";if(document.getElementsByTagName&&document.getElementById){var anchors=document.getElementsByTagName("a");for(i=0;i<anchors.length;i++){var attr=String(atype=="class"?anchors[i].className:anchors[i].getAttribute(atype));if(attr){var matches=attr.match(/([^\s])+/g);for(var j=0;j<matches.length;j++){var match=matches[j].replace(/^([\w]*)[:|][^,\s]+([,]?[^,\s]+)*$/i,"$1");var args=(matches[j].replace(match,"")).match(/[^,|:\s]+/g);if(this.storage[match]){anchors[i].onclick=this.Bind(this.storage[match], args);}}}}}},popupWindow:function(url,n,w,h,sc){var sw=screen.availWidth;var sh=screen.availHeight;lp=(sw)?(sw-w)/2:0;tp=(sh)?(sh-h)/2:0;se='height='+h+',width='+w+',top='+tp+',left='+lp+',scrollbars='+sc+',resizable=yes';win=window.open(url,n,se);win.focus();},add:function(rel, fn){if(!this.storage[rel])this.storage[rel]=fn;else throw("Behaviour already exisits for '"+rel+"'");},setPopupDimensions:function(w,h){window.__popupDims=[w,h];},setAttrType:function(a){window.__aType=a;},Bind:function(fn){var args=[];if(arguments.length>1){args=(new String(arguments[1])).split(",");}return function(){return fn.apply(this, args);};}};
/* 2007/12/05 - ND.classFunctions v0.92 - Glenn Baker - includes addClass, removeClass, hasClass, toggleClass and replaceClass */
ND.classFunctions={addClass:function(t, c){var p=new RegExp("(^|)"+c+"(|$)");if(!p.test(t.className)){if(t.className==""){t.className=c;}else{t.className+=" "+c;}}return true;},removeClass:function(t, c){var removedClass=t.className;var p=new RegExp("(^|)"+c+"(|$)");removedClass=removedClass.replace(p, "$1");removedClass=removedClass.replace(/$/, "");t.className=removedClass;return true;},replaceClass:function(t, prec, c){removeClass(t,prec);addClass(t,c);},toggleClass:function(t, c){if(hasClass(t,c)){removeClass(t,c);}else{addClass(t,c);}},hasClass:function(t, c){var p=new RegExp("(^|)"+c+"(|$)");return p.test(t.className);},init:function(){for(n in this){window[n]=this[n]}}};ND.classFunctions.init();

var setIEHovers = function(list) {
	var listItems = list.getElementsByTagName("li");

	for(var k=0; k < listItems.length; k++) {
		var node = listItems[k];
		node.onmouseover=function() {this.className+=" hover";}
		node.onmouseout=function() {this.className=this.className.replace(" hover", "");}
	}
}

var hoverIE = function() {
	// IE6 only
	if(window.ActiveXObject && window.external && (typeof window.XMLHttpRequest == "function")) {
		var ul_array = document.getElementsByTagName("ul");

		for (var i=0; i < ul_array.length; i++) {
			if(ul_array[i].parentNode.className == 'hoverable') {
				setIEHovers(ul_array[i]);
			}
		}
	}
}

/* Overlabels */
var hideLabel = function(field_id, hide){
	var field_for;
	var labels = document.getElementsByTagName('label');
	for (var i = 0; i < labels.length; i++) {
		field_for = labels[i].htmlFor || labels[i].getAttribute('for');
		if (field_for == field_id && hasClass(labels[i],"overlabel-apply")) {
			labels[i].style.textIndent = (hide) ? '-9999px' : '0px';
			return true;
		}
	}
};

var initOverLabels = function(){
	if (!document.getElementById) return;  	
	var labels, id, field;
	labels = document.getElementsByTagName('label');
	for (var i=0; i < labels.length; i++) {
	    if (labels[i].className == 'overlabel') {
			id = labels[i].htmlFor || labels[i].getAttribute('for');
			if (!id || !(field = document.getElementById(id))){continue;}
			labels[i].className = 'overlabel-apply';		
			if (field.value !== ''){hideLabel(field.getAttribute('id'), true);}
			field.onfocus = function(){hideLabel(this.getAttribute('id'), true);};
			field.onblur = function(){
				if(this.value === ''){
					hideLabel(this.getAttribute('id'), false);
				}
			};
			labels[i].onclick = function(){
				var id, field;
				id = this.getAttribute('for');
				if(id && (field = document.getElementById(id))) {
					field.focus();
				}
			};
		}
	}
};

/* Show and Hide tabs in model-image-gallery*/

$(function() {
    if(document.getElementById("jstabs"))
    {
        $('.tabbed .tabs div a').click(	
            function()
            {
		        var href = this.getAttribute('href');
		        var tabName = href.substring(href.indexOf('#')+1);
		        var tab = document.getElementById(tabName);
		        //Show the tab and activate the button
		        if (hasClass(tab ,'hidden'))
		        {
			        if (!hasClass(this.parentNode,'active'))
			        {
				        addClass (this.parentNode,'active');
			        }
			        removeClass (tab ,'hidden');	
		        }
    		
		        //Disactive other buttons 
		        var divTab= this.parentNode.parentNode.childNodes;
		        for (var i=0;i<divTab.length;i++)
		        {
			        if (divTab[i].tagName=='DIV')
			        {
				        var aTag = divTab[i].childNodes[0];
				        if (aTag.getAttribute('href')!=href)
				        {
					        if (hasClass(divTab[i],'active'))
					        {
						        removeClass (divTab[i],'active');
					        }
				        }
			        }
		        }
    		
		        //Hide other tabs
		        var tabs=new RegExp("(^)"+'tab'+"([0-9]*$)");
		        var divs = document.getElementsByTagName('div');
		        for (var i=0;i<divs.length;i++)
		        {
			        if (tabs.test(divs[i].id))
			        {
				        if (divs[i].id!=tabName)
				        {
					        if (!hasClass(divs[i],'hidden')) 
					        {
						        addClass (divs[i],'hidden');
					        }
    				    }	
	    		    }
		        }
		        return false;			
	        }
	    );
	}
})

/* Show and Hide details for the home*/

$(function() {$('#sub-nav dt a.popup').mousedown(
	function(){
		//Activate current tab
		var idDt = this.parentNode.id;
		var idDd = idDt + '-definition';
		var dtTag = document.getElementById(idDt);
		var ddTag = document.getElementById(idDd);
		if (hasClass(ddTag,'hidden')) {
			removeClass (ddTag,'hidden');
		}
		if (!hasClass(dtTag,'current')){
			addClass (dtTag,'current');
		}
		//Hidden the other tabs 
		var ddTags = document.getElementsByTagName('dd');
		for (var i=0;i<ddTags.length;i++){
			if (ddTags[i].id!=idDd){ 
				if (!hasClass(ddTags[i],'hidden')){
					addClass(ddTags[i],'hidden');
				}
			}
		}
		
		//Disactivate the links for not current tabs 
		var dtTags = document.getElementsByTagName('dt');
		for (var i=0;i<dtTags.length;i++){
			if (dtTags[i].id!=idDt){ 
				if (hasClass(dtTags[i],'current')){
					removeClass(dtTags[i],'current');
				}
			}
		}
		
		//Inject page for each tab (AJAX)
		$(ddTag).load($(this).attr("href"));
		$('.items').css({ overflow:"hidden"});
		return false;
		});})
		
$(function() {$('#sub-nav dt a.no-popup').mouseover(
	function(){
		//Activate current tab
		var dtTags = document.getElementsByTagName("dt");
		var ddTags = document.getElementsByTagName("dd");
		
	    for(var i=0; i < dtTags.length; i++) {
		
			var idDt = dtTags[i].id;
			var idDd = idDt + '-definition';
			var dtTag = document.getElementById(idDt);
			var ddTag = document.getElementById(idDd);
        if (!hasClass(ddTag,'hidden')) {
				addClass (ddTag,'hidden');
			}
			if (hasClass(ddTag,'current')) {
				removeClass (ddTag,'current');
			}

		}
		return false;
		});})
				
$(function() {$('#sub-nav dt a.popup').click(
	function(){
		return false;
	});})

$(function() {$('#sub-nav').bind('mouseleave',
	function(){
		//Close the tab
		$('#sub-nav dd:not(.hidden)').addClass('hidden');

		//Disactivate the link of the tab just hidden
		$('#sub-nav dt.current').removeClass('current');
		return false;
	});})

$(function() {$('.heading .control a').click(
	function(){
		var collapsible= $(this).parent().parent().parent();
		var collapsibleOther = $('.collapsible').not($(collapsible));
		var controlOther = $(collapsibleOther).children('.heading').children('.control');
		var contentOther = $(collapsibleOther).children('.content');
		var control= $(this).parent();
		var content = $(control).parent().next();
		if ($(control).is('.collapse')){
			$(content).slideUp("fast");
			$(control).removeClass('collapse');
			$(control).addClass('expand');
			//$(control).addClass('snippet');
			$(this).attr('title', 'Expand');
			$(contentOther).slideDown("fast");
			$(controlOther).removeClass('expand');
			$(controlOther).addClass('collapse');
			//$(controlOther).removeClass('snippet');
			$(controlOther).children('a').attr('title', 'Collapse');
		}
		else if ($(control).is('.expand')){
			$(content).slideDown("fast");
			$(control).removeClass('expand');
			$(control).addClass('collapse');
			//$(control).addClass('snippet');
			$(this).attr('title', 'Collapse');
			$(contentOther).slideUp("fast");
			$(controlOther).removeClass('collapse');
			$(controlOther).addClass('expand');
			//$(controlOther).removeClass('snippet');
			$(controlOther).children('a').attr('title', 'Expand');
		}

		return false;
	});})

$(function() {$('.featureimg a').lightBox();})

//homeflash
$(function() {
	$("body").addClass("js-enabled");
    if(document.getElementById("flashHome"))
	{
		var so = new SWFObject("/global/swf/rotator.swf", "Rotator", "971", "578", "9", "#FFFFFF");
		//var so = new SWFObject("/global/swf/XmasCard_01_CL.swf", "Rotator", "971", "578", "9", "#FFFFFF");
		
		so.addParam("wmode", "transparent");
		thepath = $("#flashHome").attr("rel");
		so.addVariable("path", thepath);
		so.write("flashHome");
	}
})

var myInit = function(){hoverIE();initOverLabels();};
ND.addLoadListener(myInit);
