function Accordian() {

	var togglers = $('#catAccordian h2');
	var elements = "#catAccordian li ul";

	$("a[rel*='external']").attr({ target: "_blank" });
	
	$(elements).hide();
	togglers.click(
	function(e) {
		e.preventDefault();
		var checkElement = $(this).next();
			if((checkElement.is(elements)) && (checkElement.is(':visible'))) {
			$(elements + ':visible').slideUp(300);
			return false;
		}
		if((checkElement.is(elements)) && (!checkElement.is(':visible'))) {
			$(elements + ':visible').slideUp(300);
			checkElement.slideDown(300);
			return false;
		}
    });

    openSelected();
}

function openSelected() {
    var selElement = "#catAccordian li ul li a.selected:first";
    $(selElement).parent().parent().slideDown(300);
}



function theRotator() {
	//Set the opacity of all images to 0
	$('#rightCol .pods .partners li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('#rightCol .pods .partners li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('#rightCol .pods .partners li.show')?  $('#rightCol .pods .partners li.show') : $('#rightCol .pods .partners li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#rightCol .pods .partners li:first') :current.next()) : $('#rightCol .pods .partners li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

$(document).ready(function(){
						   
	Cufon.replace('h1.chunk', { fontFamily: 'ChunkFive' });
	Cufon.replace('h2.chunk', { fontFamily: 'ChunkFive' });
	
	theRotator();
	Accordian();
	$(document).pngFix();
	
	var arrLis = $("#mycarousel li a")
	var selectedIndex;
	
	arrLis.each(
	function(intIndex){
		
		var el = arrLis[intIndex];
		
		if ($(el).hasClass("selected")){
				selectedIndex = intIndex+1;
		}
		
	});
	
	carousel()
	function carousel(){
		$('#mycarousel').jcarousel({
		vertical: true,
		scroll:12,
		start: selectedIndex
		});
	}

	$('.productList .tipTrigger').tooltip({
		relative: 'true',
		position: 'bottom right',
		offset: [-107, 0]
	});

	$('.mainProduct .winePromise').tooltip({
		relative: 'true',
		position: 'bottom right',
		offset: [-35, 0]
	});

	$('.mainProduct .storeClearance').tooltip({
		relative: 'true',
		position: 'bottom right',
		offset: [-35, -310]
	});

	$('.mainProduct .tipTrigger').tooltip({
		relative: 'true',
		position: 'bottom right',
		offset: [-200, 0]
	});
	
	
    if ($('#curiouswines')) {      
        //      $('curiouswinessubmit').addEvent('load', function(evt) {
        //          new Event(evt).stop();
                $('#curiouswines').submit();
        //     });
    }
	
// CarouFredSel
	
	var slideCounter = $('#bannerSlider li').size();
	$("#bannerSlider li:not(:first) a").attr("tabIndex", "-1");	
	$("#bannerSlider").carouFredSel({
		items: 1,
		scroll: {
			pauseOnHover: true,
			easing: "easeInOutExpo",
			duration: 1000,
			onBefore: function(oldItems, newItems) {
				oldItems.children('a').attr("tabIndex", "-1");
				newItems.children('a').removeAttr("tabIndex");
			}
		},
		auto: 5000,
		pagination: {
			container: ".carouselNav ul",
			anchorBuilder: function( nr ) {
				var str  = '<li><a href="#">';
					str += '</a></li>';
				return str;
			}
		}
	});

/*	if($("tag")){
		var flash = new FlashObject("/_images/flash/tag.swf?Price=59.99&wasPrice=99.99", "tag", "184", "82", "9", "#ffffff");
		flash.addParam("WMODE","transparent");
		flash.addParam("menu","false");
		flash.addParam("quality","high");
		flash.addParam("movie", "tag.swf?Price=59.99&wasPrice=99.99");
		flash.write("tag");
	}

	if($("price")){
		var flash = new FlashObject("/_images/flash/price.swf?Price=250.50", "price", "130", "45", "9", "#ffffff");
		flash.addParam("WMODE","transparent");
		flash.addParam("menu","false");
		flash.addParam("quality","high");
		flash.addParam("movie", "price.swf?Price=250.50")
		flash.write("price");
	} */

});
