
if(window['debug'] === undefined) {
  window.debug = function(q,w,e,r){  
    try { if (typeof console != 'undefined') console.log.apply(console,arguments); } 
    catch(err){ if (typeof console != 'undefined')  console.log(q,w,e,r); }
  }
}

// catch all document.write() calls
document._write = document.write;
document.write = function(q){ 
  if (q.match(/docwriteregextopassthrough/)) document._write(q);  
  debug('document.write(): ',q); 
}



/*
  Object: Infor
*/
window.INFOR = {

  // common domready code that runs on all pages
  common : {
 		//code that effects the visual look of the page   
		init: function(){
			
			$.browser.ie6 = ($.browser.msie && jQuery.browser.version < 7);
			if ($.browser.ie6){
				INFOR.common.pngfix('#content, ul.menu li.logo, ul.menu li, ul.menu li.end, b.lt, b.rt');
			}

	    	//fire bug lite
	    	if (!!document.location.search.match(/fbug=true/) ){
	        	$.getScript('http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js',function(){ firebug.init(); });
	    	}

	    	// catch ajax errors
	    	$(document).ajaxError(function(){ debug('ajax error:',arguments); });
				
		},

		//code that doesn't effect the look of the page		
		finalize: function(){		

		},

		/*****************************************************************************************************************************
		*  Below are commonly used functions that will be called only on certain pages.  Call them using INFOR.common.nameoffunction()
		******************************************************************************************************************************/
		
		//horizontal scroller for homepage, nation and whoisnot
		horizontalScroll : function(){
			//scroller
			//Get our elements for faster access and set overlay width
			var div = $('div.scroller'),
				ul = $('ul.scroller'),
				ulPadding = 15;

			//Get menu width
			var divWidth = div.width();

			//Remove scrollbars	
			div.css({overflow: 'hidden'});

			//Find last li in container
			var lastLi = ul.find('li:last-child');

			//When user move mouses over scroller
			div.mousemove(function(e){
				//so we recalculate width each time
				var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
				var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
				div.scrollLeft(left);
			});
			
		},// end of INFOR.common.horizontalScroll()
		
		
		slideshow : function(){
			    var $active = $('.slideshow li.active');
			    if ( $active.length == 0 ) {
						$active = $('.slideshow li:last');
					}
			    var $next =  $active.next().length ? $active.next() : $('.slideshow li:first');
			    $active.removeClass('active');
			    $next.addClass('active');
			
	
		}, // end of INFOR.common.slideshow()
		
		
		// pngfix for IE6
	  // e.g. FOO.pngfix('img.bigProdShot,a.thumb');
	  pngfix : function(sel){
	    // conditional comments for inclusion of that js.
	    if (typeof DD_belatedPNG == 'undefined'){  return; 
	    } else {
	      // delay pngfix until window onload
	      $(window).load(function(){ $(sel).each(function(){ DD_belatedPNG.fixPng(arguments[1]); }); }); 
	    }
	  }//INFOR.common.pngfix
	
    
 }, // end of INFOR.common()


		/**************************************************************
		*  These are the pages.  They are defined by an ID on the BODY tag
		INFOR.util looks to see what the ID is on <body> and then fires the page specific code.
    -SL 
		***************************************************************/

 homepage : {
			init: function(){
				INFOR.common.horizontalScroll();
				
				$(function() { setInterval( "INFOR.common.slideshow()", 7000 ); });

      			// $('.newsScroller').fitted();
			
				//homepage specific PNGFIX	
				if ($.browser.ie6){
		      		INFOR.common.pngfix('#homepage h1, .right h3, .newsScroller, .newsScroller span');
				}
				}		
 			}, // end INFOR.homepage()

 	whois : {
		init: function(){ 
			$('.scroll').jScrollPane({ showArrows:true });
		
			//whois specific PNGFIX	
			if ($.browser.ie6){
				INFOR.common.pngfix('#whois h1, .jScrollPaneTrack ');
			}
		
			$('#flash').flash({  
				swf: 'flash/whois/who_is.swf',
				flashvars: {
					xmlFile:"flash/xml/who_is_EN.xml"		
				},
				width: 464, 
				height: 261
			});
		}	
	},//end INFOR.whois()
	
	whoisnot : {
		init: function(){
			$('.scroll').jScrollPane({ showArrows:true });
				
			INFOR.common.horizontalScroll();
			$(function() {
			    setInterval( "INFOR.common.slideshow()", 7000 );
			});
				
			//whoisnot specific PNGFIX	
			if ($.browser.ie6){
				INFOR.common.pngfix('#whoisnot h1, #whoisnot #top .right');
			}		
		}
	}, //end INFOR.whoisnot()

	resources : {
		init: function(){

			// resources specific PNGFIX	
			if ($.browser.ie6){
				INFOR.common.pngfix('#resources h1');
			}
			
		}
	}, //end INFOR.whoisnot()
	
	nation : {
		init: function(){ 
			INFOR.common.horizontalScroll();
			//nation specific PNGFIX	
			if ($.browser.ie6){
				INFOR.common.pngfix('#nation h1, .nation');
			}
		}
	}//end INFOR.nation()

},//END VAR INFOR NAME SPACE

	/**************************************************************
	*  The magic that triggers the dom ready code based on page id.
		  Based on Paul Irish code  http://paulirish.com/2009/markup-based-unobtrusive-comprehensive-dom-ready-execution/  
 							-SL 
	***************************************************************/

UTIL = {

  fire : function(func,funcname, args){

    var namespace = INFOR;  // indicate your obj literal namespace here

    funcname = (funcname === undefined) ? 'init' : funcname;
    if (func !== '' && namespace[func] && typeof namespace[func][funcname] == 'function'){
      namespace[func][funcname](args);
    } 

  }, //end of INFOR.util.fire

  loadEvents : function(){

    var bodyId = document.body.id;

    // hit up common first.
    UTIL.fire('common');
		//hit page specific via  body ID
    UTIL.fire(bodyId);
    UTIL.fire('common','finalize');

  } 

}// end of INFOR.util


// == COOKIE METHODS (thx to PPK @ Quirksmode.org) ========
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function launchUnSized(url,cat,act,lab) {
	//alert(cat + act + lab);
	window.open(url);
	trackItem(cat,act,lab);
	
}

function launchSized(url,w,h,cat,act,lab) {
	//alert(cat + act + lab);
	window.open(url,"downwithbigerp_window","scrollbars=1,width="+w+",height="+h);
	trackItem(cat,act,lab);
	
}

// kick it all off here ---------------------------- Yay!
$(document).ready(UTIL.loadEvents);