function styleWriter() {
   if ((navigator.userAgent).indexOf("Safari")!=-1) {
	   document.write('<link href="css/safari.css" media="screen" rel="Stylesheet" type="text/css" />')
   } else if ((navigator.appName).indexOf("Opera")!=-1) {
	   document.write('')
   }
 }
styleWriter();

function scrollIt($scrollable, amount) {
	var rightPadding = 0;
	var scroll = $scrollable.scrollLeft() + amount;
	if (scroll < 0) {
		scroll = 0;
	} else if ($scrollable.attr("scrollWidth")) {
			var max = $scrollable.attr("scrollWidth") - $scrollable.innerWidth() + rightPadding;
			if (scroll > max) scroll = max;
	}
	$scrollable.animate({scrollLeft: scroll}, 500);
}

function scrollTo($scrollable, $target) {
	var leftAdjustment = 0;
	scrollIt($scrollable, $target.offset().left - $scrollable.offset().left - leftAdjustment);
}

function scrollToAnchor(anchor) {
	var $target = jQuery("a[name=" + anchor + "]");
	var $scrollable = $target.parents("#scrollable");
	if ($scrollable.length == 1 && $target.length == 1) {
		scrollTo($scrollable, $target);
		return false;
	}
}

function scrollToMe() {
	return scrollToAnchor(this.hash.slice(1));
}

function hookToLinks() {
	jQuery("a[href^=#]").click(scrollToMe);
}

function hookToArrows() {
	jQuery("div.scroll.left").click(function() {scrollIt(jQuery("#scrollable"), -600); return false; });
	jQuery("div.scroll.right").click(function() {scrollIt(jQuery("#scrollable"), 600); return false; });
}

function populateCarousel() {
	jQuery.each(carouselItems, function(index, value) {
		if (value) {
			var html = '<td><a name="' + escape(value[0]) + '" href="' + value[1] + '"><div><img src="' + value[2] + '" /></div><span>' + value[3] + '</span></a></td>';
			var $element = jQuery(html);
			if (value[1].charAt(0) == '#') {
				$element.children("a").click(scrollToMe);
			}
			$element.insertBefore("#filler");
		}
	});
	var fillerWidth = jQuery("#scrollable").width() - jQuery("#filler").prev().width();
	jQuery("#filler").css("width", fillerWidth);
	jQuery("#filler").css("min-width", fillerWidth);
}
		

jQuery(document).ready(function($) {

	$('#accordion dt').click(function() {
			$(this).next().toggle("slow");
			$(this).toggleClass("collapsed");
			$(this).toggleClass("on");
		    return false;
	});
	hookToArrows();
	hookToLinks();
	populateCarousel();
	if (carouselSelected) {
		scrollToAnchor(carouselSelected);
	}
});

function NewWindow(u,n,w,h,f,p,x,y){var    ws=window.screen?1:0,m=Math,C='center',R='random',M='custom',sw=screen.availWidth,sh=screen.availHeight,T=(p==C&&ws)?(sh-h)/2:(p==R&&ws)?(m.floor(m.random()*(sh-h))):(p==M)?y:100,L=(p==C&&ws)?(sw-w)/2:(p==R&&ws)?(m.floor(m.random()*(sw-w))):(p==M)?x:100,s='width='+w+',height='+h+',top='+T+',screeny='+T+',left='+L+',screenx='+L;s+=(!f||f=='')?'':','+f;win=window.open(u,n,s);if(win.focus)win.focus();}

function GrowFromCenter(u,n,w,h,f){var WO=(d=document,WW=WH=100,s=window.screen,ws=s?1:0,sw=ws?s.availWidth:800,sh=ws?s.availHeight:640,x=(sw-WW)/2,y=(sh-WH)/2,l=(sw-w)/2,t=(sh-h)/2,s='width='+WW+',height='+WH+',top='+y+',screeny='+y+',left='+x+',screenx='+x,s+=(d.layers)?',resizable':'',s+=(!f||f=='')?'':','+f,W=self[n]=window.open('',n,s),(W&&!W.closed)?1:0);while(WW!=w||WH!=h){if(WO&&WW<w){W.moveTo((sw-WW)/2,(sh-WH)/2);    W.resizeTo(WW,WH);WW*=1.3}if(WO&&WW>w){WW=w;W.moveTo((sw-WW)/2,(sh-WH)/2);W.resizeTo(WW,WH)}if(WO&&WH<h){W.moveTo((sw-WW)/2,(sh-WH)/2);W.resizeTo(WW,WH);WH*=1.3}if(WO&&WH>h){WH=h;W.moveTo((sw-WW)/2,(sh-WH)/2);W.resizeTo(WW,WH)}}if(d.layers){W.outerHeight=h;W.outerWidth=w;}W.moveTo(l,t);W.document.location=u;W.focus();}

function win(u,n,w,h,f,p,x,y){
var ws=window.screen?1:0,sw=screen.availWidth,sh=screen.availHeight,m=Math,C='center',R='random',M='custom',T=(p==C&&ws)?(sh-h)/2:(p==R&&ws)?(m.floor(m.random()*(sh-h))):(p==M)?y:100,L=(p==C&&ws)?(sw-w)/2:(p==R&&ws)?(m.floor(m.random()*(sw-w))):(p==M)?x:100,s='width='+w+',height='+h+',top='+T+',left='+L;s+=(!f||f=='')?'':','+f,W=self[n]?self[n]:'';
if("object"==typeof W && !W.closed){
        W.blur();
            if(W.location!=u){W.location=u;}
        W.resizeTo(w,h);
        W.moveTo(L,T);
        W.focus();}
else{self[n]=window.open(u,n,s);self[n].focus();}}