var $jq = jQuery.noConflict();


/** Create faux brand nav from filter **/
/**
function createFauxBrandNav() {
	
	var brandsNav = $jq('#panel-navigation-brands');
	var brandItems = $jq('select#field_product_brand option');
	
	if (brandItems.length > 1) {
		brandItems.each(function() {
			
			if ($(this).attr('value')) {
				var brandURL = '/store/search/brand/' + $jq(this).attr('value').replace(' ','-') + '/';
				brandsNav.append('<a href="' + brandURL + '">' + $jq(this).text() + '</a>');
			}
			
		});
	} else {
		$jq('#sg-brandnav').remove();
	}
}
**/

/** Move the crappy site footer logos **/
function sgRelocateElements() {
	
	// Move the footer NS Logos
	$jq('#sitefooter a').appendTo('#footer-badge');	
	$jq('#sitefooter, #bookmarks').remove();
	
	// Make Reviews add go in reviews box
	$jq('div#reviewrating').appendTo('#productreviews .sg-block-content');
	
	// Show promotions at end of content body.
	$jq('#specialoffers').appendTo('#customcontent');
}

/** Hover Intent for big & small buttons **/
function sgButtonsIntent() {
	$jq('a.button-small, a.button-big').hover(
		function() { $jq(this).css('opacity',.8); },
		function() { $jq(this).css('opacity',100); }
	);
}

/** Tweak The Search Form **/
function sgSearchBarMod() {
	
	// Prepend our search text
	$jq('form#search_form > table tr').prepend('<td valign="middle" align="center" style="width:159px;"><span class="sg-search-label">PRODUCT SEARCH</span></td>').find('td:eq(3)').remove();
	
	// Remove size rules for search box
	//$jq('input#keyword-search-box').removeAttr('size','');
	
	// Remove padding on button
	$jq('input#keyword-search-button').removeAttr('style','');
	
	// Search Table Padding
	$jq('#search-options table.search-table').attr('cellpadding',0);
	
}


/** Remove unwanted bs in store panel navigation **/
function cleanPanelNavigation() {
	
	// Prepend "Brands" To Nav
	//$jq("#panel-navigation").prepend('<a href="/store/content/335/Brands/" id="department-brands" class="link-department">BRANDS</a>');
	
	// Remove Auto Formatting Crap
	$jq("#panel-navigation br").remove(); 
	$jq("#panel-navigation span").remove();
}


/** Text Field Placeholders **/
function sgSearchPlaceholder() {

	$jq('input.placeholder').each(function() {

		var el = $jq(this);
		var value = el.attr('value');

		el.attr('placeholder',value);

		el.focus(function() {
			if ($jq(this).attr('value') == el.attr('placeholder')) {
				el.attr('value','');
			}
		});

		el.blur(function() {
			if ($jq(this).attr('value') == '') {
				el.attr('value',el.attr('placeholder'));
			}

		});

	});

}

$jq(document).ready(function() {
	sgRelocateElements();
	sgButtonsIntent();
	sgSearchBarMod();
	sgSearchPlaceholder();
});