//post a form by ajax
/*parameters:
button: the button that triger the ajax call. it will hide the button while success returns (optional if custom handler function provided)
updateContainer: the container where to put hte ajax response (optional if custom handler function provided)
beforeSend: function to run before send
onSuccess: function to handle the successfull request it will pass (msg,status of the request) as argument
*/
var cAjaxForm = function(o){
	myAjax = new Object;
	myAjax.button = o.button;
	myAjax.updateContainer= o.updateContainer;
	myAjax.beforeSend = o.beforeSend?o.beforeSend:function(){ $(myAjax.button).css('visibility','hidden'); };
	myAjax.onSuccess = o.onSuccess?o.onSuccess:function(msg,status){ $(myAjax.updateContainer).html(msg); $(myAjax.button).css('visibility','visible');};
	myAjax.form = o.form?o.form:'';
	if( myAjax.form ){
		$.ajax({
				type: $(myAjax.form)[0].method,
				url: $(myAjax.form)[0].action ,
				data: $(myAjax.form).serialize(),
				beforeSend: myAjax.beforeSend,
				success: function(msg,status){
						myAjax.onSuccess(msg,status);
						}
			});
		}
	}
	
var cAjaxRequest = function(o){
	myAjax = new Object;
	myAjax.beforeSend =  o.beforeSend?o.beforeSend:function(){};
	myAjax.onSuccess = o.onSuccess?o.onSuccess:function(msg,status){ alert(msg) };
	myAjax.method = o.method?o.method:'GET'
	myAjax.url = o.url;
	myAjax.data = o.data?o.data:'';
	if( myAjax.url ){
		$.ajax({
				type: myAjax.method,
				url: myAjax.url ,
				data: myAjax.data,
				beforeSend: myAjax.beforeSend,
				success: function(msg,status){
						myAjax.onSuccess(msg,status);
						}
			});
		}
	}
	
//toggle hide show a div
function toggleHideShow(v,anim){
	if( typeof(anim) == 'undefined') anim = 'fast';
	$(v).slideToggle(anim);
	}
	
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;
	}

function eraseCookie(name) {
	createCookie(name,"",-1);
	}
    
    
    
    
    
        
        
//Home page left nav flyout menu 
$(function(){ 
    
    $('#mainleft ul li ul li').hover(function() {
        var flyout_ul = $(this).find('ul');        
        if(flyout_ul.size()>0){
            $(flyout_ul).fadeIn('slow');
        }
    },
    function() {
        var flyout_ul = $(this).find('ul');        
        if(flyout_ul.size()>0){
            $(flyout_ul).fadeOut('slow');
        }
    });
    
    
    $('.all_occasion_cards').hover(function() {
        $('.flyout_menu').fadeIn('slow');
    },
    
    function() {
        $('.flyout_menu').fadeOut('fast');
    });
    
});        
