//var $jq = jQuery.noConflict();


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

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

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

/** Tweak The Search Form **/
function sgSearchBarMod() {
	
	// Prepend our search text
	$('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
	//$('input#keyword-search-box').removeAttr('size','');
	
	// Remove padding on button
	$('input#keyword-search-button').removeAttr('style','');
	
	// Search Table Padding
	$('#search-options table.search-table').attr('cellpadding',0);
	
}


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


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

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

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

		el.attr('placeholder',value);

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

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

		});

	});

}

/** Cleanup the checkout page **/
function _sg_onestep_cleanup() {
	
	// Check / set a class name to referece if we've done this already
	if ($('html#checkout-cleaned').length > 0 || $('body#page-checkoutstep2').length == 0) return;
	
	// Add our custom 'fixed' classname
	$('html').attr('id','checkout-cleaned');
	
	// Build a better layout
	var checkout_panels = $('#checkout-panels');
	
	var column_one = $('#checkout-first-column').addClass('checkout-third');
	var column_two = $('<div id="checkout-second-column" class="checkout-third"></div>');
	var column_three = $('<div id="checkout-third-column" class="checkout-third"></div>');
	
	// Relocate some panels
	$('#checkout-section-shipping, #checkout-section-checkoutplugin').appendTo(column_two);
	$('#checkout-section-coupon, #checkout-section-comment, #checkout-section-basket').appendTo(column_three);
	
	// Put our newly created panels back in the dom
	checkout_panels.append(column_two).append(column_three);
	
	// Make it much easier / cleaner to pick payment method.
	if ($('#checkout-section-checkoutplugin > div').not('.plugin-data').length > 1) {
		
		var payment_options = $('<div id="clean-payment-options" class="checkout-panel"></div>');
		$('#checkout-section-checkoutplugin h4').clone().appendTo(payment_options).end();
		$('#checkout-section-checkoutplugin h4').text('Payment Details');
		$('#checkout-section-checkoutplugin > div').not('.plugin-data').appendTo(payment_options);
		
		
		payment_options.prependTo(checkout_panels).append('<br style="clear:both;" />');
		
	}
	
	
}

$(document).ready(function() {
	sgRelocateElements();
	sgButtonsIntent();
	sgSearchBarMod();
	sgSearchPlaceholder();
	_sg_onestep_cleanup();
	
	// Kill vspace on IE7
	$('.product-category-pic img.image-thumb').attr('hspace',0).attr('vspace',0);
});
