

//---------------------
// 2 Column List
//---------------------

function twoCols(src, type) {
	var origList = src;

	if (origList.getElementsByTagName('LI').length != 1)
	{

		var leftList = document.createElement(type);
		var rightList = document.createElement(type);
		var container = document.createElement('div');

		var items = origList.getElementsByTagName('LI');

		var itemsLength = items.length/2;
		for (i = 0; i < itemsLength; i++) {
			leftList.appendChild(items[0]);
		}

		itemsLength = items.length;

		for (i = 0; i < itemsLength; i++) {
			rightList.appendChild(items[0]);
		}
		container.appendChild(leftList);
		container.appendChild(rightList);

		leftList.setAttribute('class', 'left clearfix');
		rightList.setAttribute('class', 'right clearfix');
		container.setAttribute('id','portList');
		if (document.all) {
			leftList.setAttribute('className', 'left clearfix');
			rightList.setAttribute('className', 'right clearfix');
			container.setAttribute('id','portList');
		}
		if (type == 'ol') {
			rightList.setAttribute('start', leftList.getElementsByTagName('LI').length + 1 );
		}
		origList.parentNode.replaceChild(container, origList);

	}
	
}

function allTwoCols (whichclass, type) {
	var uls = document.getElementsByTagName(type);
	for (var i=0; i< uls.length; i++) {
		if (uls[i].getAttribute('class') == whichclass || uls[i].getAttribute('className') == whichclass) {
			twoCols(uls[i], type.toLowerCase());
		}
	}
}

function checkEnter(e, fn){ //e is event object passed from function invocation
	var characterCode; // literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	} else {
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		fn();
		return false;
	} else {
		return true;
	}
}

function limitChars(textarea, limit, infodiv)
{
	var text = document.getElementById(textarea).value;	
	var textlength = text.length;
	var info = document.getElementById(infodiv);

	if(textlength >= limit)
	{
		info.innerHTML = 'Maximum of '+limit+' characters reached.';
		document.getElementById(textarea).value = text.substr(0,limit);
		return false;
	}
	else
	{
		info.innerHTML = 'You have '+ (limit - textlength) +' characters left.';
		return true;
	}
}



$(function(){
	$('#content').jScrollPane({scrollbarMargin: 15});
});

/*$(function(){
	$('.scrollme').jScrollPane({scrollbarMargin: 15});
});*/

$(function(){
	var $content = $('#content');
	$content.jScrollPane({animateTo:true});
	$('a.scrollto').bind(
		'click',
		function()
		{
			var targetElementSelectorString = $(this).attr('rel');
			$content[0].scrollTo(targetElementSelectorString);
			return false;
		}
	);
});

$(document).ready(function(){ 
	$('#navWineDetails').localScroll({
	   target: '#wd-scroller',
	   axis: 'xy',
	   queue: true,
	   hash: false
	});
});
$(document).ready(function(){ 
	$('#wd-awards p').localScroll({
	   target: '#wd-scroller',
	   axis: 'xy',
	   queue: true
	});
});
$(document).ready(function(){ 
	$('.returnToAwards').localScroll({
	   target: '#wd-scroller',
	   axis: 'xy',
	   queue: true
	});
});

$(document).ready(function(){ 
	$('#wr-1 .review-paging').localScroll({
	   target: '#wr-1-scroller',
	   axis: 'xy',
	   queue: true
	});
});
$(document).ready(function(){ 
	$('#wr-2 .review-paging').localScroll({
	   target: '#wr-2-scroller',
	   axis: 'xy',
	   queue: true
	});
});
$(document).ready(function(){ 
	$('#wr-3 .review-paging').localScroll({
	   target: '#wr-3-scroller',
	   axis: 'xy',
	   queue: true
	});
});
$(document).ready(function(){ 
	$('#wr-4 .review-paging').localScroll({
	   target: '#wr-4-scroller',
	   axis: 'xy',
	   queue: true
	});
});
$(document).ready(function(){ 
	$('#wr-5 .review-paging').localScroll({
	   target: '#wr-5-scroller',
	   axis: 'xy',
	   queue: true
	});
});
$(document).ready(function(){ 
	$('#navLocal').localScroll({
	   target: '#wd-scroller',
	   axis: 'xy',
	   queue: true
	});
});
$(document).ready(function(){ 
	$('#wd-downloads p').localScroll({
	   target: '#wd-scroller',
	   axis: 'xy',
	   queue: true,
	   hash: false
	});
});


$(document).ready(function(){ 
	$.localScroll.hash({
		target: '#wd-scroller',
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1500
	});
});

$(document).ready(function(){ 
	if ( document.location.hash == "#wd-news") { selectClass('navLocal', 'w-1'); }
	if ( document.location.hash == "#wd-events" ) { selectClass('navLocal', 'w-2'); }
	if ( document.location.hash == "#wd-promotions" ) { selectClass('navLocal', 'w-3'); }
	if ( document.location.hash == "#wd-pastevents" ) { selectClass('navLocal', 'w-4'); }
	if ( document.location.hash == "#wd-press" ) { selectClass('navLocal', 'w-5'); }
});



function selectClass(nav, item) {
	$('#' + nav + ' li').removeClass("selected");
	$('#' + nav + ' li.' + item).addClass("selected");
}

$(document).ready(function(){ 
	$.scrollTo.defaults.axis = 'xy'; 	
	$.scrollTo.defaults.hash = false; 	
	$.scrollTo.defaults.queue = true; 	

	$('#wd-scroller').scrollTo(0);
});

$(document).ready(function() {
	/*
		apply a class of first-child/last-child to elements to fake
		the first-child/last-child pseudo-selector for IE6
	*/
	$('#portList .left > li:first').addClass('first-child');
	$('#portList .right > li:first').addClass('first-child');
	$('#portList.splitList > li:first').addClass('first-child');
	$('#navLocal ul > li:last').addClass('last-child');
});


$(document).ready(function(){ 
	$('.photoslideshow').innerfade({ 
		speed: 750,
		timeout: 4000 
	});	
});

$(function() {
	var fancyboximages = $('#photo a:not(.static), a.productimage[rel=lightbox], .popup');
	if( fancyboximages.size() > 0) {
		fancyboximages.fancybox({ 'callbackOnShow': function(){
				$("#fancy_close").show();
			}
		});
	}
});


// Pressing enter in login fields to submit form
$(document).ready(function() {
	$("ul.membership input").keypress(function(evt) {
		if(evt.which || evt.keyCode) {
			if((evt.which == 13) || (evt.keyCode == 13)) {
				location =    document.getElementById('cmdLogin').href;
            return false;   
         } else {
            return true;
			}
		}
	});
});
// remove unnecessary qs
$(document).ready(function() {
	var form = $("form[action*=/privatebin/order-online.aspx]");
	if (form.length > 0) { $(form).attr("action", $(form).attr("action").replace(/\?type=\d/, "")); }
});

$.fn.pulse =  function(time, iterations)
{
    if (!time)
      time = 2000;
	if (!iterations)
	  iterations = 1;
	  
	for (var i = 0; i < iterations; i++) {
		this.animate({ opacity: 0.1 }, time / 2).animate({ opacity: 1 }, time / 2);		
    }
    return this;
}