var $j = jQuery.noConflict();

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

// Xin's code

	var bodya, bodyspan;
	var bd = "." + $j("body").attr("class").split(" ")[0];
	var nav = $j("li.mainnav");
	var pad = $j(".navbar .navbarwrapper ul li a.navitem span");
	var padh = $j("#page .navbar .navbarwrapper ul li.hovered a.navitem span")
	var ccdrop = $j("ul.cc_dropdown li.cc");
	var navz = $j(".navbar");
	var bodyz = $j(".contentbody");
	var headerz = $j(".headerwrapper");
	
	var degrees = $j("#networkbar #weatherspot .temperature").html();
	degrees = degrees.substring(0,degrees.length-2);
	$j("#networkbar #weatherspot .temperature").html(degrees + "<img src='http://www.montrealgazette.com/images/header/weather_symbol.gif' alt='' />");
	if((window.location+"").indexOf("shoplocal.com")>=0) $j("#networkbar #weatherspot").css("display", "none");
	else $j("#networkbar #weatherspot").css("display", "inline");
	
	$j("input.input_newspaper").focus(function(){
		$j("input.input_newspaper").css("color", "#333333");
		$j("input.input_newspaper").css("font-style", "normal");
		$j("input.input_newspaper").css("font-size", "12px");
	});
	$j("input.input_newspaper").blur(function(){
		$j("input.input_newspaper").css("color", "#aaaaaa");
		$j("input.input_newspaper").css("font-style", "italics");
		$j("input.input_newspaper").css("font-size", "11px");
	});
	
	
	if (bd.substring(1) == "home"){
		bodya = $j("#page .navbar .navbarwrapper ul li#home a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#home a.navitem span", bd);
	}
	else if (bd.substring(1) == "news"){
		bodya = $j("#page .navbar .navbarwrapper ul #news a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul #news a.navitem span", bd);
	}
	else if (bd.substring(1) == "opinion"){
		bodya = $j("#page .navbar .navbarwrapper ul #opinion a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul #opinion a.navitem span", bd);
	}
	else if (bd.substring(1) == "business"){
		bodya = $j("#page .navbar .navbarwrapper ul li#business a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#business a.navitem span", bd);
	}
	else if (bd.substring(1) == "sports"){
		bodya = $j("#page .navbar .navbarwrapper ul li#sports a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#sports a.navitem span", bd);
	}
	else if (bd.substring(1) == "entertainment"){
		bodya = $j("#page .navbar .navbarwrapper ul li#entertainment a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#entertainment a.navitem span", bd);
	}
	else if (bd.substring(1) == "life"){
		bodya = $j("#page .navbar .navbarwrapper ul li#life a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#life a.navitem span", bd);
	}
	else if (bd.substring(1) == "travel"){
		bodya = $j("#page .navbar .navbarwrapper ul li#travel a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#travel a.navitem span", bd);
	}
	else if (bd.substring(1) == "technology"){
		bodya = $j("#page .navbar .navbarwrapper ul li#technology a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#technology a.navitem span", bd);
	}
	else if (bd.substring(1) == "health"){
		bodya = $j("#page .navbar .navbarwrapper ul li#health a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#health a.navitem span", bd);
	}
	else if (bd.substring(1) == "cars"){
		bodya = $j("#page .navbar .navbarwrapper ul li#cars a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#cars a.navitem span", bd);
	}
	else if (bd.substring(1) == "jobs"){
		bodya = $j("#page .navbar .navbarwrapper ul li#jobs a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#jobs a.navitem span", bd);
	}
	else if (bd.substring(1) == "homes"){
		bodya = $j("#page .navbar .navbarwrapper ul li#homes a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#homes a.navitem span", bd);
	}
	else if (bd.substring(1) == "classifieds"){
		bodya = $j("#page .navbar .navbarwrapper ul li#classifieds a.navitem", bd);
		bodyspan = $j("#page .navbar .navbarwrapper ul li#classifieds a.navitem span", bd);
	}

	function showit(){
		//top layer ad fix
		$j(navz).css("z-index","2");
		$j(headerz).css("z-index","2");
		$j(bodyz).css("z-index","1");

		$j(this).addClass("hovered");
		$j(bodya).css("background-color","transparent");
		$j(bodyspan).css("background-color","transparent");
		// IE 8 fix
		$j(pad).css("padding", "8px 6px 8px 6px");
	}

	function hideit(){
		//top layer ad fix
		$j(navz).css("z-index","1");
		$j(headerz).css("z-index","1");
		$j(bodyz).css("z-index","2");

		$j(this).removeClass("hovered");
		$j(bodya).css("background-color","#990002");
		$j(bodyspan).css("background-color","#990002");
		// IE 8 fix
		$j(pad).css("padding", "8px 6px 8px 6px");
	}
	
	$j(".subnav", nav).fadeTo("fast", .95);
	$j(nav).hover(showit, hideit);
	$j(ccdrop).hover(function(){$j(this).addClass("showdrop");}, function(){$j(this).removeClass("showdrop");});


		function sectionOver() {
		}

		//Display only the default
		function sectionOut() {
			var status = $j('body').attr('class').split(" ")[0];
			$j('#'+status).find('ul').addClass('on');
		}	
		
		//Feature Box - Homes Travel and Cars
		$j("a.featureitem").hoverIntent({
				sensitivity: 1, 
				interval: 5, 
				over: sliderOver, 
				timeout: 0, 
				out: sliderOut
			});

		function sliderOver() {
			$j('a.featureitem').removeClass('active');
			$j(this).addClass('active');
			$j('#slidercontent').removeClass();
			if( $j(this).is(".featureitem01") ) {
				$j(this).parents('#featureslider').find('#slidercontent').addClass('content01');
			}; 
			if( $j(this).is(".featureitem02") ) {
				$j(this).parents('#featureslider').find('#slidercontent').addClass('content02');
			};
			if( $j(this).is(".featureitem03") ) {
				$j(this).parents('#featureslider').find('#slidercontent').addClass('content03');
			};
			if( $j(this).is(".featureitem04") ) {
				$j(this).parents('#featureslider').find('#slidercontent').addClass('content04');
			};
			if( $j(this).is(".featureitem05") ) {
				$j(this).parents('#featureslider').find('#slidercontent').addClass('content05');
			};
		}

		function sliderOut() {
		}	
	
		//Feature Box - Homes Travel and Cars
		$j("a.headlinetab").hoverIntent({
				sensitivity: 1, 
				interval: 5, 
				over: featureOver, 
				timeout: 0, 
				out: featureOut
			});

		function featureOver() {
			$j('a.headlinetab').removeClass('on');
			$j(this).addClass('on');
			$j('#featurebox').removeClass();
			if( $j(this).is(".headlinetab01") ) {
				$j(this).parents('#featurebox').addClass('content01');
			}; 
			if( $j(this).is(".headlinetab02") ) {
				$j(this).parents('#featurebox').addClass('content02');
			}; 
			if( $j(this).is(".headlinetab03") ) {
				$j(this).parents('#featurebox').addClass('content03');
			}; 
		}

		function featureOut() {
		}	

		//Photo section
		$j("a.sectionopen").click(function() {
		$j(this).hide();
    	$j(this).parent(".newssection").find(".newsblocks").slideDown("slow");
		$j(this).parent(".newssection").find("a.sectionclose").show("slow");
    	return false;
  		})

	 $j("a.sectionclose").click(function() {
		$j(this).hide();
		$j(this).parent(".newssection").find(".newsblocks").slideUp("fast");
		$j(this).parent(".newssection").find("a.sectionopen").show("slow");
    	return false;
  		});

		//Breaking News
	 	$j(".breakingnews .morelink li a").mouseover(function() {
		$j(this).parent("li").parent(".morelink").parent(".featurecontent").parent("#featurewidget").slideUp("fast");
    	return false;
  		});
	});

function redirect(selectObj, selectTrgt) {
	switch(selectTrgt) {
		case "popup":
			window.open(selectObj.options[selectObj.selectedIndex].value,'Broadcast','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
			break;    
		default:
			document.location = selectObj.options[selectObj.selectedIndex].value;
	}
}

//Set Class
function setClass(objectID,newClass) {
	var object = document.getElementById(objectID);
	object.className = newClass;
}

//Index Page Breaking News Alert
function breakingNews()
{
	var bn = document.getElementById('breakingnews');
	var cbn = document.getElementById('cns_breakingnews');
	
	var bnh = bn.offsetHeight;
	var cbnh = cbn.offsetHeight;

	if( bnh > 0 )
		cbn.style.display ='none';
}