var $j = jQuery.noConflict();

$j(window).load(function() {

/* ==============================================================================================================
 * Get current URL
============================================================================================================== */
	// variables
	var pathname = window.location.pathname;
	
	pathname = pathname.toLowerCase().replace('http://iwebagency.com/', ''); // -------------------- URL to lowercase. Replaces 'http://iwebagency/' with nothing
	pathname = pathname.replace(/\//g, '-'); // ---------------------------------------------------- Replaces forward slashes with dashes



/* ==============================================================================================================
 * Get text within <li> of main menu
============================================================================================================== */
	$j('#menudrop #cmm-menu-horizontal-light li a').each(function(i, d) {
		// variables
		var item	= $j(this).text();
		
		item = item.toLowerCase().replace(/\s+/g, '-').replace(/\./g, '');
		$j(this).addClass('menuitem-' + item);
	});



/* ==============================================================================================================
 * Set height for dropdown menu items
============================================================================================================== */
	// variables
	var num		= $j('#menudrop #cmm-menu-horizontal-light > li a').not('ul li ul a').length;
	var cycle	= 0;	
	
	$j('#menudrop #cmm-menu-horizontal-light > li a').not('ul li ul a').each(function(i, d) {
		$j(this).parent().addClass('item' + cycle);
		
		//variables
		var dd_P_height		= $j('li.item' + cycle + ' p').height();
		var dd_UL_height	= $j('li.item' + cycle + ' ul').first().height();

		if(dd_P_height > dd_UL_height) {
			$j('li.item' + cycle + ' p').css('height', dd_P_height);
			$j('li.item' + cycle + ' ul').first().css('height', dd_P_height);
		} else {
			$j('li.item' + cycle + ' p').css('height', dd_UL_height);
			$j('li.item' + cycle + ' ul').first().css('height', dd_UL_height);		
		}
		
		cycle++;
	});



/* ==============================================================================================================
 * Set active state to menu
============================================================================================================== */
	if(pathname == '-') {
		$j('body').addClass('home');
		$j('a.menuitem-home').parent().addClass('active');
	} else {
		$j('body').addClass(pathname);
	}



/* ==============================================================================================================
 * Move featured slider into spot-right position.
============================================================================================================== */
	if( $j('.home #content #featured-item').length ) {
		$j('.home #content #featured-item').appendTo('.home .spotlight #spot-right .execphpwidget');
	}



/* ==============================================================================================================
 * Checks to see if spotlight items are present.
 * If not, delete spotlight div.
 * If one is present, remove the other.
 * If both, get height and set both to larger height.
============================================================================================================== */
	if( $j('#page .spotlight #spot-left').text() == '' && $j('#page .spotlight #spot-right').text() == '' ) {
		$j('#page .spotlight').remove();
	} else if( $j('#page .spotlight #spot-left').text() != '' && $j('#page .spotlight #spot-right').text() == '') {
		$j('#page .spotlight #spot-right').remove();
	} else if( $j('#page .spotlight #spot-left').text() == '' && $j('#page .spotlight #spot-right').text() != '') {
		$j('#page .spotlight #spot-left').remove();
	} else {
		$j('#page .spotlight #spot-left').addClass('half');
		$j('#page .spotlight #spot-right').addClass('half');
		
		//variables
		var height_spot_left	= $j('#page .spotlight #spot-left').height();
		var height_spot_right	= $j('#page .spotlight #spot-right').height();
		
		if( height_spot_left > height_spot_right ) {
			$j('#page .spotlight #spot-left').css('height', height_spot_left);
			$j('#page .spotlight #spot-right').css('height', height_spot_left);
		} else {
			$j('#page .spotlight #spot-left').css('height', height_spot_right);
			$j('#page .spotlight #spot-right').css('height', height_spot_right);
		}
	}
	
});
