function miniCart() {
	this.items = [];
	this.subtotal = 0.00;
	this.curIndex = -1;
	this.timeout = 0;
}

miniCart.prototype.next = function() {
	this.curIndex = ++this.curIndex % this.items.length;
	this.display();
}

miniCart.prototype.previous = function() {
	this.curIndex--;
	if(this.curIndex < 0)
		this.curIndex = this.items.length-1;
	this.display();
}

miniCart.prototype.add = function(newMiniCartItem) {
	this.items[this.items.length] = newMiniCartItem;
	if(this.curIndex == -1)
		this.curIndex = 0;
}

// Display the curIndex in the minicart
miniCart.prototype.display = function() {
	if(this.curIndex == -1) return;
	var p = this.items[this.curIndex];
	$('#mc-pName').text(p.name);
	$('#mc-pStyle').text(p.style);
	$('#mc-pSize').text(p.size);
	$('#mc-pColor').text(p.color);
	$('#mc-pPrice').html(p.amount + "@" + p.price.toFixed(2) + "&nbsp;&nbsp;<span style='color:red'>" + parseFloat(p.price * p.amount).toFixed(2) + "</span>");
	$('#mc-pImage > img').attr('src', decodeURIComponent(p.thumbnail));
}

function miniCartItem() {
	this.name = "";
	this.style = "";
	this.size = "";
	this.color = "";
	this.amount = 0;
	this.price = 0.00;
	this.thumbnail = "";
}

function blackout() {
	this.b = $('#blackout');
	this.m = $('#bo-messageContainer');
	this.l = $('#bo-loader');
}


blackout.prototype.resize = function() {
	this.b.height($(window).height());
	this.b.width($(window).width());
}

blackout.prototype.center = function(elm) {
	var w = elm.width(),
	    h = elm.height(),
	    sh = 0;

	if (navigator.userAgent.indexOf("MSIE") > -1) {
    sh = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;		
	}	else {
		sh = window.pageYOffset;
	}

	elm.css({
		'left': (elm.parent().width() - w)/2,
		'top' : sh + $(window).height() / 3 - h/2
	});
}

blackout.prototype.bindScroll = function(elm) {
	var h;

	if(navigator.userAgent.indexOf("MSIE 6") >= 0)
		return;
	
	$(window).bind('scroll', function(event) {
		if (navigator.userAgent.indexOf("Firefox") > -1) {
			h = window.pageYOffset;
		}
		else {
      h = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;		
    }
		elm.stop(true);
		elm.animate({
			'left': (elm.parent().width() - elm.width())/2,
			'top' : h+$(window).height()/3 - elm.height()/2
		}, 500, 'swing');
	});
}

blackout.prototype.error = function(s) {
	var is_ie = navigator.userAgent.indexOf("MSIE");
	if (is_ie < 0) { //not IE
		this.resize();
	}
	this.l.hide();

	this.bindScroll(this.m);
	$(this.m).find('blockquote').html(s);
	this.center(this.m);
	if (is_ie < 0) { //not IE
		this.b.show();
	}
	this.m.show();
}

blackout.prototype.showLoader = function() {
	var is_ie = navigator.userAgent.indexOf("MSIE");
	if (is_ie < 0) { //not IE
		this.resize();
	}
	this.m.hide();

	this.bindScroll(this.l);
	this.center(this.l);
	if (is_ie < 0) { //not IE
		this.b.show();
	}
	this.l.show();
}

blackout.prototype.show = function(id) {
	var is_ie = false;
	var ieversion = false;
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
		ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 		is_ie = true;
	}
	
	if(!is_ie || ieversion >= 8) {
 		this.resize();
	}
	this.m.hide();
	this.l.hide();
	if(!is_ie || ieversion >= 8) {
		this.b.show();
	}
	if(id != null) {
		this.bindScroll($(id));
		this.center($(id));
		$(id).show();
	}


}

blackout.prototype.hide = function(id) {
	$(window).unbind('scroll');
	this.b.hide();
	this.l.hide();
	this.m.hide();

	if(id != null)
		$(id).hide()
}

function submitForm() {
	document.loginform_logout.submit();
}

function submitenter(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
		myfield.form.submit();
		return false;
	}
	else
		return true;
}
