var $j = jQuery.noConflict();
$j(document).ready(function(){ 
	//search field 
	$j('.text').each(function() {
		var text = this.value;
		$j(this).css('color', '#666');
		$j(this).focus(function() {
			if(this.value == text) {
				this.value = '';
				$j(this).css('color', '#333');
			}
		});
		$j(this).blur(function() {
			if(this.value == '') {
				$j(this).css('color', '#666');
				this.value = text;
			}
		});
	});
	
	// homepage banner
	$j('#slideshow').cycle({
		fx:     'fade',
		speed:  'slow',
		timeout: 4000,
		pager:  '#slideshow_nav',
		pagerAnchorBuilder: function(idx, slide) {
		// return sel string for existing anchor
		return '#slideshow_nav li:eq(' + (idx) + ') a';
		}
	});
		
	$j('#direct').click(function() {
		$j('#slideshow_nav li:eq(2) a').triggerHandler('click');
		return false;
	});
	$j(".item:last-child").css("margin-right", 0);
	
	
	// bucket slide on homepage
	$j('#top_center_bucket_slides').cycle({
		fx:      'scrollHorz',
		timeout:  5000,
		prev:    '#prev',
		next:    '#next'
	});
	
	
	// accordion for product filters
	$j('h4.filter_type').prepend('<img class="plus-minus" src="/skin/frontend/enterprise/default/images/css/minus.gif">');
	$j('.filter_options input, .filter_options label').css({opacity: 1.0, visibility: 'visible'});
	$j('h4.filter_type').click(function() {
		var choices = $j(this).next('.filter_options');
		var choices_content = $j(choices).find('input, label, a');
		if($j(choices).is(':visible')) {
			$j(choices_content).animate({opacity: 0.0}, 200, function () { $j(choices).slideUp('fast'); });
			$j(this).find('img').attr('src','/skin/frontend/enterprise/default/images/css/plus.gif');
		} else {
			$j(choices).slideDown('fast', function() { $j(choices_content).animate({opacity: 1.0}, 200); });
			$j(this).find('img').attr('src','/skin/frontend/enterprise/default/images/css/minus.gif');
		}
    }); 
	
	// product list equal heights
	if ($j('.prod_list_height').length) {
		$j(".prod_list_height").equalHeights(); 
	}
	
	// tabs on product details page
	if ($j('#prod_left2 .tab_content').length || $j('#prod_right .tab_content').length) {
		if ($j('#prod_left2 .tab_content').length) {
			$j('#prod_left2 .panes div.tab_content').show();
			$j("#prod_left2 .special_deals_tab .item").equalHeights();
			$j("#prod_left2 .related_items_tab .item").equalHeights();
			$j("#prod_left2 .tab_content").equalHeights();
			$j("#prod_left2 .tab_content").resize(function(){
				$j("#prod_left2 .tab_content").equalHeights();
			});
			$j('#prod_left2 .panes div.tab_content').hide();
		}
		/* no tabs now in the right column
		if ($j('#prod_right .tab_content').length) {
			$j("#prod_right .tab_content").equalHeights();
			$j("#prod_right .tab_content").resize(function(){
				$j("#prod_right .tab_content").equalHeights(); 
			});
		}
		*/
		$j("ul.tabs").tabs("div.panes div.tab_content");
	}
	  

	/* top banner randomizer */
	if ($j('h1#page_title').length) {
		var rand_num = Math.floor(Math.random()*$j('#hidden_banners img').size());
		var banner_src = $j("#hidden_banners img").eq(rand_num).attr('src');
		$j('h1#page_title').css('background-image', 'url('+banner_src+')');
	}
	
	/* add Mac class */
	if(navigator.userAgent.indexOf('Mac') > 0) {
		$j('body').addClass('mac');	
	} 
});
