
function parseURL(url) {
	out = new Array();
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		out[pair[0]] = pair[1];
	}
	return out;
} 
function getUrlVars(url){
	return url.split("?")[1];
}
function addToCart(){
	showOverlay();
	showOverLoader();
	$.get( '/cart/add-item?pc=js', getUrlVars(this.href),_cartData);
	return false;
}
function _cartData(data){
	checkCartStatus();
	hideOverLoader();
	data = eval(data);
	if(data.status == 'success'){
		showTopMessage(data.html);
		if(!checkMyBubble()){
			showBubble(5000);
		}
	}
	if(data.status == 'fail'){
		showTopMessage(data.html);
	}
	postAjax();
}

function checkCartStatus(){
	$.get( '/cart/add-item?pc=js', 'action=checkStatus',_cartStatus);
}
function _cartStatus(data){
	data = eval(data);
	if(data.items > 0){
		$('#cart-panel').find('.cart-panel-text').html('<span>You have '+data.items+' items in your cart.  <a href="/cart/view">View Cart</a></span>');
		$('#cart-panel').fadeIn(500);
	}
}

function checkMyBubble(){
	if(!readCookie('bub')){
		showBubble(10000);
		createCookie('bub','1',1);	
		return true;
	}else{
		return false;	
	}
}
function showBubble(timeout){
	$('#cart-bubble').fadeIn(500);
	if(timeout){
		setTimeout(hideBubble,timeout);
	}
}
function hideBubble(){
	$('#cart-bubble').fadeOut(500);
}

function fixSlideShow(sin,sout,sopt){
	
	var h = $(sin).children('.description').html();
	$(sin).children('.description').html('');
	$(sin).children('.description').html(h);

	$(sin).children('.description').css({filter:"alpha(opacity=100)"});
	$(sin).children('.description').hide();
	$(sin).children('.description').show();
	
	var h = $(sout).children('.description').html();
	$(sout).children('.description').html('');
	$(sout).children('.description').html(h);

	$(sout).children('.description').css({filter:"alpha(opacity=100)"});
	$(sout).children('.description').hide();
	$(sout).children('.description').show();
}


// vertical positioning in the viewport

(function($){
  $.fn.vCenter = function(options) {
    var pos = {
      sTop : function() {
        return window.pageYOffset || document.documentElement && document.documentElement.scrollTop ||	document.body.scrollTop;
      },
      wHeight : function() { 
        return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
      }
    };
    return this.each(function(index) {
      if (index == 0) {
        var $this = $(this);
        var elHeight = $this.height();
		    var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
        $this.css({
          position: 'absolute',
          marginTop: '0',
          top: elTop
        });


      }
    });
  };

})(jQuery);


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

