var $j = jQuery.noConflict();
jQuery(document).ready(function(){


$j('a').click(function() {
	this.blur();
	});


// FRONT PAGE SLIDESHOW //
function crenSlideshow(){				
	$j('.ss').css('background-image','none');
	
	 $j('#ss1').cycle({
	    fx:    'fade', 
	    timeout:12000,
		containerResize: 0,
		cleartype:  1,
	    delay:  -9000 
	});
	 $j('#ss2').cycle({ 
	    fx:    'fade', 
	    timeout:12000,
		containerResize: 0,
		cleartype:  1,
	    delay:  -6000 
	});
	 $j('#ss3').cycle({ 
	    fx:    'fade', 
	    timeout:12000,
		containerResize: 0,
		cleartype:  1,
	    delay:  -3000 
	});
	 $j('#ss4').cycle({ 
	    fx:    'fade', 
	    timeout:12000,
		containerResize: 0,
		cleartype:  1,
	    delay:  0000 
	});
}


// NAVIGATION PAGE LOADING //
	var body_tag = $j("body").css("id");
		//alert(body_tag);
	if ( body_tag == "home"){
		$j("#m_b_wrapper").css('display','block');
	}

	// INIT
	if($j("body").attr("id") == "home"){
		//$j("#slideshow").css('height' ,'0px');
		//$j("#slideshow").stop().animate( { height: '214px' } , "slow" );
		$j("body").attr("id","home");
		$j('#content').html("<small><em></em>Loading . . . </small>");
	   	$j('#content').fadeIn('slow');
		$j('#content').load('http://www.crenchicago.com/cren-wp/wp-content/themes/cren/ajax-index.php', function(){
			//$j("#content").fadeIn("slow");			
		});
		$j("#m_b_wrapper").fadeIn("slow");
		crenSlideshow();
	};


	$j("#header").click(function(){
		if($j("body").attr("id") != "home"){
			$j.address.value($j(this).attr('href'));  
		    $j('#content').fadeOut("slow", function(){
		$j("#slideshow").css('height' ,'50px');
				$j("#slideshow").stop().animate( { height: '214px' } , "slow" );
				$j("body").attr("id","home");
				$j('#content').html("<small><em></em>Loading . . . </small>");
			   	$j('#content').fadeIn('slow');
				$j('#content').load('http://www.crenchicago.com/cren-wp/wp-content/themes/cren/ajax-index.php', function(){
					//$j("#content").fadeIn("slow");			        
				});
				$j("#m_b_wrapper").fadeIn("slow");
				crenSlideshow();
			});
		};
		return false;
	});


	$j('.ajax-link').click(function(){
		var no_start = $j(this).attr('href').indexOf('=');
		var page_no = $j(this).attr('href').slice( no_start );
		var link_id = $j(this).attr('id');
		if ( $j('body').attr('id') != $j(this).attr('id') ){
			$j.address.value($j(this).attr('href'));  
			$j('#m_b_wrapper').fadeOut('slow');
		    $j('#content').fadeOut('slow', function(){
				$j('#menu').animate( { paddingTop: '0px' } , 'slow', function(){
				    //$j('#content *').fadeOut("slow");//$j('#content + p').fadeOut("slow");
				    $j('body').attr('id', link_id );
					$j('#content').html("<small><em></em>Loading . . . </small>");
				   	$j('#content').fadeIn('slow');
				    $j('#content').load('http://www.crenchicago.com/cren-wp/wp-content/themes/cren/ajax-page.php?p' + page_no, function(){
				    	$j('#content *').fadeIn('slow');
					});
				});
			});
		};

	    return false; 
	});


	$j('.ajax-cat').click(function(){
		var no_start = $j(this).attr('href').indexOf('=');
		var page_no = $j(this).attr('href').slice( no_start );
		var link_id = $j(this).attr('id');
		if ( $j('body').attr('id') != $j(this).attr('id') ){
			$j.address.value($j(this).attr('href'));  
			$j('#m_b_wrapper').fadeOut('slow');
		    $j('#content').fadeOut('slow', function(){
				$j('#menu').animate( { paddingTop: '0px' } , 'slow', function(){
				    //$j('#content *').fadeOut("slow");//$j('#content + p').fadeOut("slow");
				    $j('body').attr('id', link_id );
					$j('#content').html("<small><em></em>Loading . . . </small>");
				   	$j('#content').fadeIn('slow');
				    $j('#content').load('http://www.crenchicago.com/cren-wp/wp-content/themes/cren/ajax-category.php?cat=1&p' + page_no, function(){
				    	$j('#content *').fadeIn('slow');
					});
				});
			});
		};

	    return false; 
	});


	//Officers AJAX Loader
	$j('ul.officers li a').click(function(){
		// get the page_id from the GET attribute.
		var no_start = $j(this).attr('href').indexOf('=');
		var page_no = $j(this).attr('href').slice( no_start ); 
	    var ajax_target = $j(this).attr('href');
		// Animate
	    $j('#ajax_content').fadeOut('slow', function(){
			$j(this).show();
			// Animate 
			$j('#ajax_content').html("<small>Loading . . . </small>");
			$j('#ajax_content').load('http://www.crenchicago.com/cren-wp/wp-content/themes/cren/ajax-officer.php?p'+page_no, function(){
			   	//$j('#ajax_content').fadeIn('slow', function(){
			   		//$j('#ajax_content').style.removeAttribute("filter");
			   	//});

			});
		});

	    return false; 
	});




// NAVIGATION ROLLOVERS //
	
	$j("#menu ul li:hover").removeClass('dd'); //remove css hover effect if js enabled.


	$j('.dropdown').each(function () {
		$j(this).parent().eq(0).hoverIntent({
			timeout: 100,
			over: function () {
				var current = $j('.dropdown:eq(0)', this);
				current.slideDown(100);
			},
			out: function () {
				var current = $j('.dropdown:eq(0)', this);
				current.fadeOut(200);
			}
		});
	});
	
	$j('.dropdown a').hover(function () {
		$j(this).stop(true).animate({paddingLeft: '8px'}, {speed: 100, easing: 'easeOutBack'});
	}, function () {
		$j(this).stop(true).animate({paddingLeft: '0'}, {speed: 100, easing: 'easeOutBounce'});
	});


/*  OLD CODE ///// 
	$j("ul#topnav li").hover (function(){ //When li is moused-over...
		//Following events are applied to the subnav itself (moving subnav up and down)
		//Drop down the subnav on click
		//$j(this).find("ul.subnav").stop().slideDown('slow').show(); 
		$j(this).find("ul.subnav").show(); 

	},function(){
		//When the mouse hovers out of the subnav, move it back up
		$j(this).find("ul.subnav").hide(); //stop animation
		//$j(this).find("ul.subnav").stop().slideUp('slow').hide(); 
	});
*/

});
