$(document).ready(function(){
	$('.product_inside').mouseenter(function(){
		$(this).find('.quick_view_but').stop();
		$(this).find('.quick_view_but').css('top', '270px');
		$(this).find('.quick_view_but').animate({
			top: '70px'
		}, 'fast');
	});
	
	$('.product_inside').mouseleave(function(){
		$(this).find('.quick_view_but').stop();
		$(this).find('.quick_view_but').animate({
			top: '270px'
		}, 'fast');
	});
	$('li.minicart').hover(function () {
            var target = $(this).children('ul');
            $.browser.msie ? target.hide() : target.slideUp(150);
        },
        function () {
            var target = $(this).children('ul')
            $.browser.msie ? target.show() : target.slideDown(150);
        }
    );
});

function loadQuickPage(purl){
	$.ajax({
		type: 'get',
		url: purl,
		success: function(msg){
			$('#quick_view_inner').html(msg);	
			
		}
	});
}

function showQuickView(pid){
	$('#overlay').show();
	$('#hide_overlay').show();
	$('#quick_loading').show();
	$('#quick_view_inner').html('');
	$('#quick_view_box').fadeIn('fast', function(){
		// done so load in the details.
		loadQuickPage('/quick_view.php?prod=' + pid + '&nt=' + Date().getTime);
	});
}

function hideQuick(){
	$('#overlay').fadeOut('fast');	
	$('#quick_view_box').fadeOut('fast', function(){
		
	});
}
	
function checkStock(val){
	if (val <= 0){
		$("#addCartButton").hide();
		$("#quant").hide();
		$("#outStock").show();
	} else {
		$("#addCartButton").show();
		$("#quant").show();
		$("#outStock").hide();
	}
}
	
function addCart(pid){
	if ($("#optn0").val() == ''){
		alert('Please select a size.');
		return;
	}
	if ($("#quant").val() < 1){
		alert("Please enter a quantity.");
		return;
	}
	$('#minLoader').show();
	$.ajax({
		type: 'post',
		cache: false,
		url: '/quickcart.php',
		data: 'id='+pid+'&optn0='+$('#optn0').val()+'&mode=add&quant='+$('#quant').val(),
		success: function(msg){
			create("default", { title:'Added Item to your Bag', text:'<table border="0" width="100%" cellpadding="8" cellspacing="0"><tr><td><img src="'+$("#quickImage1").attr('src')+'" /></td><td><h3>' + $("#quant").val() + " - " + $("#quickName").html()+'</h3></td></tr></table>'});
			$('.minicart').load('/cartcount.php', function(){			
				$('#minLoader').hide();
				hideQuick();			
				$('html, body').animate({scrollTop: '0px'}, 800);
			});
		},
		error: function(jqXHR, textStatus, errorThrown){
			create("default", { title:'Added Item to your Bag', text:'<table border="0" width="100%" cellpadding="8" cellspacing="0"><tr><td><img src="'+$("#quickImage1").attr('src')+'" /></td><td><h3>' + $("#quant").val() + " - " + $("#quickName").html()+'</h3></td></tr></table>'});
			$('.minicart').load('/cartcount.php', function(){			
				$('#minLoader').hide();
				hideQuick();			
				$('html, body').animate({scrollTop: '0px'}, 800);
			});
		}
		
	});	
}

function addCart2(pid){
	if ($("#optn0").val() == ''){
		alert('Please select a size.');
		return;
	}
	if ($("#quant").val() < 1){
		alert("Please enter a quantity.");
		return;
	}
	$('#minLoader').show();
	$.ajax({
		type: 'post',
		cache: false,
		url: '/quickcart.php',
		data: 'id='+pid+'&optn0='+$('#optn0').val()+'&mode=add&quant='+$('#quant').val(),
		success: function(msg){
			create("default", { title:'Added Item to your Bag', text:'<table border="0" width="100%" cellpadding="8" cellspacing="0"><tr><td><img src="'+$("#quickImage1").attr('src')+'" /></td><td><h3>' + $("#quant").val() + " - " + $("#bigName").html()+'</h3></td></tr></table>'});
			$('.minicart').load('/cartcount.php', function(){			
				$('#minLoader').hide();
				hideQuick();			
				$('html, body').animate({scrollTop: '0px'}, 800);
			});
		},
		error: function(jqXHR, textStatus, errorThrown){
			create("default", { title:'Added Item to your Bag', text:'<table border="0" width="100%" cellpadding="8" cellspacing="0"><tr><td><img src="'+$("#quickImage1").attr('src')+'" /></td><td><h3>' + $("#quant").val() + " - " + $("#bigName").html()+'</h3></td></tr></table>'});
			$('.minicart').load('/cartcount.php', function(){			
				$('#minLoader').hide();
				hideQuick();			
				$('html, body').animate({scrollTop: '0px'}, 800);
			});
		}
		
	});	
}

function create( template, vars, opts ){
	return $('#container').notify("create", template, vars, opts);
}


$(document).ready(function(){
	$("#container").notify({
		template: 'default'
	});
	var options = { 
        beforeSubmit:	showRequest,
        success:		showResponse,
		dataType:		'json' 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#ajaxmail').ajaxForm(options); 	
});

function notifyStock(pid){
	$("#stockLoader").show();
	$.ajax({
		type: 'post',
		url: '/notifystock.php',
		data: 'id='+pid+'&email='+$('#emailnotify').val()+'&opt='+$('#optn0').val(),
		success: function(msg){
			$("#stockLoader").hide();
			
			if (msg == '1'){
				
				create("default", { title:'Added', text:'You will be notified when this item is back in stock.'});
			} else {
				alert(msg);
			}
		}
	});	
}
function objToString (obj) {
    var str = '';
    for (var p in obj) {
        if (obj.hasOwnProperty(p)) {
            str += p + '::' + obj[p] + '\n';
        }
    }
    return str;
}


function showRequest(formData, jqForm, options) { 
	$('#messageLoad').show();
    return true; 
} 
 
// post-submit callback 
function showResponse(data)  { 
	if (data['Type'] == 'Error'){
		alert(data['Message']);
	}
	if (data['Type'] == 'Success'){
		$('#ajaxmail').html(data['Message']);
		// Do success	
	}
	$('#messageLoad').hide();
} 


	var win = null;

function newWindow(mypage,myname,w,h,features) {

  var winl = (screen.width-w)/2;

  var wint = (screen.height-h)/2;

  if (winl < 0) winl = 0;

  if (wint < 0) wint = 0;

  var settings = 'height=' + h + ',';

  settings += 'width=' + w + ',';

  settings += 'top=' + wint + ',';

  settings += 'left=' + winl + ',';

  settings += features;

  win = window.open(mypage,myname,settings);

  win.window.focus();

}

function popupImage(){

	newWindow('http://www.footzyrolls.com/images/footzyrollsizechart.jpg', 'footzyrollssizechart','830','700','scrollbars');

}

function popupImage2(){

	newWindow('http://www.footzyrolls.com/sizechart.html', 'footzyrollssizechart','830','300','scrollbars');	

}


function goCart(msd){
	
	$("#hiddenmode").val(msd);
	$("#hiddencart").submit();
	
}
