/**
 * FIX IE6 IMAGE FLICKER PROBLEM
 *
 */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

$(document).ready(function() {
    /* Initialize text resizing. */
    $('.toolbar li.textsize a').click(function() {
        setActiveStyleSheet($(this).attr('rel'));

        $('.toolbar li.textsize a').removeClass('lit');
        $(this).addClass('lit');

        return false;
    });
});


$(document).ready(function(){

	var currLocation = 0;

	var maxHeight = 0;
	var maxWidth = 0;

	var scrollerWidth = $('.slideshow .scroller').width() - 1;

	$('.slideshow .scroller ul li').each(function(i){
		maxWidth += $(this).width() + 21;

		if(maxHeight < $(this).height())
		{
			maxHeight = $(this).height();
		}
	});

	$('.slideshow .scroller').height(maxHeight).width(scrollerWidth);
	$('.slideshow .scroller ul').width(maxWidth);


	$('.slideshow a.next').click(function(){

		/* Slide images to the right. */
		if((currLocation + 121) < scrollerWidth)
		{
			currLocation += 121;

			$('.slideshow a.prev').removeClass('disabled');

			$('.slideshow .scroller ul').animate({
				marginLeft: '-=121px'
			}, 500);
		}

		/* Update nav controls. */
		if((currLocation + 121) >= scrollerWidth)
		{
			$(this).addClass('disabled');
		}

		return false;
	});

	$('.slideshow a.prev').click(function(){

		/* Slide images to the left. */
		if(currLocation > 0)
		{
			currLocation -= 121;

			$('.slideshow a.next').removeClass('disabled');

			$('.slideshow .scroller ul').animate({
				marginLeft: '+=121px'
			}, 500);
		}

		/* Update nav controls. */
		if(currLocation <= 0)
		{
			$(this).addClass('disabled');
		}

		return false;
	});

});

/* google analystics for tracking downloads and external sites - start */

if (document.getElementsByTagName) { 
        // Initialize external link handlers 
        var hrefs = document.getElementsByTagName("a"); 
        for (var l = 0; l < hrefs.length; l++) { 
                //protocol, host, hostname, port, pathname, search, hash 
                if (hrefs[l].protocol == "mailto:") { 
                        startListening(hrefs[l],"click",trackMailto); 
                } else if (hrefs[l].hostname == location.host) { 
                        var path = hrefs[l].pathname + hrefs[l].search; 
                        var isDoc = path.match(/(?:doc|eps|exe|jpg|pdf|png|ppt|svg|vsd|xls|zip)($|\&)/); 
                        if (isDoc) { 
                                startListening(hrefs[l],"click",trackExternalLinks); 
                        } 
                } else { 
                        startListening(hrefs[l],"click",trackExternalLinks); 
                } 
        } 
} 

function startListening (obj,evnt,func) { 
        if (obj.addEventListener) { 
                obj.addEventListener(evnt,func,false); 
        } else if (obj.attachEvent) { 
                obj.attachEvent("on" + evnt,func); 
        } 
} 

function trackMailto (evnt) { 
        var href = (evnt.srcElement) ? evnt.srcElement.href : this.href; 
        var mailto = "/mailto/" + href.substring(7);
        if (typeof (pageTracker) == "object") pageTracker._trackPageview(mailto);
}

function trackExternalLinks (evnt) { 
        var e = (evnt.srcElement) ? evnt.srcElement : this; 
        while (e.tagName != "A") { 
                e = e.parentNode; 
        } 
        var lnk = (e.pathname.charAt(0) == "/") ? e.pathname : "/" + e.pathname; 
        if (e.search && e.pathname.indexOf(e.search) == -1) lnk += e.search; 
        if (e.hostname != location.host) lnk = "/external/" + e.hostname + lnk;

        if (typeof (pageTracker) == "object") pageTracker._trackPageview(lnk); 
}
/* google analystics for tracking downloads and external sites - end */