//Javascript
$.noConflict();

jQuery(function($) {
	function runOnLoad() { location.href = "#wrap"; }
	
	function loadIframe(){
		if (location.search.length > 0){
			url = unescape(location.search.substring(1))
			window.frames["gallery"].location=url
		}
	}
	
	var newsHeader1 = $("#sidebar .SingleContentWidget h3:eq(0)").text();
	var newsHeader2 = $("#sidebar .SingleContentWidget h3:eq(1)").text();
	
	$("#sidebar .SingleContentWidget h3:eq(0)").html("<a href='/newsroom/'>" + newsHeader1 + "</a>");
	$("#sidebar .SingleContentWidget h3:eq(1)").html("<a href='/newsroom/'>" + newsHeader2 + "</a>");
	
	$("#nav li:last-child").css('border', 'none');
	//$("#nav .sub1 li:last-child").css('clear', 'right');
	$("#subnav li:last-child").css('border', 'none');
	$("#sidebar .SingleContentWidget p,#sidebar .SingleContentWidget hr, #sidebar .SingleContentWidget span, #sidebar .SingleContentWidget ul").css('display', 'none');
	$("#sidebar .WidgetHolder:last p").css('display', 'block');
	$("#sidebar .SingleContentWidget h3").css('display', 'none');
	$("#sidebar .SingleContentWidget h3:eq(0),#sidebar .SingleContentWidget h3:eq(1)").css({'display': 'block', 'line-height' : '12pt', 'font-size' : '10pt'});
	$("#sidebar .SingleContentWidget:first").css({'border-bottom': '1px solid #DBDBDB', 'margin-bottom': '10px;', 'height': '100px'});
	
	var mainHeight = $("#main").height();
	var sidebarHeight = $("#sidebar").height();
	
	if(mainHeight>sidebarHeight){
		$("#sidebar").css('border', 'none');
		$("#main").css('borderRight', '1px solid #DBDBDB');
	}
	
	var pathname = window.location.pathname;
	
	if(pathname == '/downloads'){
		$("#content-wrap .clear").css('display', 'none');
		$("#sidebar").css({'border': 'none', 'width': '0', 'display': 'none'});
		$("#main").css({'float': 'none','border': 'none', 'width': '960px', 'margin-left': '0'});
		$("#main p").css({'margin': '0', 'padding': '0', 'height': '700px', 'border-top': '1px solid #DBDBDB'});
		$("#main br").css('display', 'none');
	}
	
	$("li.top").hover(
	  function () {
		$('ul', this).css('display', 'block');
	  }, 
	  function () {
		$('ul', this).css('display', 'none');
	  }
	);
	
	
	$("a.grouped_elements").fancybox({
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});
	
	function noError(){return true;}
	window.onerror = noError;
	
	//document.write(pathname);
})(jQuery);

