$(document).ready(function(){

//alert('loaded');

		$('#miniaccount').html('<div class="spinner"><img src="/images/ajax-loader-small.gif"></div>'); 	
	   $('#miniaccount').load('/ajax_miniaccount.php');
	
	$("a.fancybox").fancybox();
	



    		   
 		$dlg = $('#dlg')
    		$dlg.dialog({ 	autoOpen: false });

	
  reloadComments();

$dlg.dialog({
    open: function(){
        // hide any flash objects
        $('object').css('visibility', 'hidden');
        // hide any flash embeds
        $('embed').css('visibility', 'hidden');
    },
    close: function(){
        // show any flash objects
        $('object').css('visibility', 'visible');
        // show any flash embeds
        $('embed').css('visibility', 'visible');
        //
    }
});


 $(".menu-list-level2").each(function () {
	
				$(this).hide();
	
});
		
	$( "#tabs" ).tabs();
	
$('.menu-level1').live("click",function(event){

			var subCat = $(this).find('.menu-list-level2');
			
				if (subCat.length == 0) {
}else
			
				if(subCat.is(":visible")){
					
				}else{
			
				$('.menu-list-level2').slideUp();
				subCat.slideDown();
				event.preventDefault();
		}
	 		
});
		
	$(".menucurrent").each(function () {
		
						//$(this).parent().show();
						//$(this).find('.menu-list-level2').show();
});
         
    		 $dlg = $('#dlg');
 
    		$dlg.dialog({ 	autoOpen: false });
	
	 	$(".LINK").live("hover",function() {
		
		
			$(this).css("cursor", "pointer"); 
		 }); 


$('.search-directory').submit(function(e){
     e.preventDefault(); //Prevent the normal submission action
     var form = this;

     // ... Handle form submission
     var searchin =  $(form).find('[name=searchin]').val();
     var searchfor =  $(form).find('[name=searchfor]').val();
		
     	$('#content').html('<img src="/images/ajax-loader-small.gif">'); 	
			$('#content').load("/ajax_searchDirectory.php", { 'searchfor':searchfor,'searchin':searchin } );
});






		$(".search-buttdddon").live("click",function(event){
			var FORM  = $(this).parent('form');
			formParams = FORM.serialize();
				alert(formParams);
			
			var SEARCHFOR = $(this).siblings('input').val();
			//alert(SEARCHFOR);
			 	
				
				
				
	
	  event.preventDefault();
	 });
		
$('.LOGIN').live("click",function(event){
	

	$dlg.load('/ajax_login.php');
                 		$dlg.dialog( "option", "width", 600 );
                		$dlg.dialog( "option", "height", 330 );
                		$dlg.dialog( "option", "modal", true );
                		$dlg.dialog( "option", "resizable", false );
                		$dlg.dialog( "option", "title", "Login to Promo Marketing..." );
                		$dlg.dialog('option', 'buttons',false);
                		
                   	$dlg.dialog( "open");
             
                
                



	event.preventDefault();
});

$('#login_password').live("keyup",function(e) {
                	
    if (e.keyCode == 13) {
       
        signin();
    }
});



$('#button_account').live("click",function(event){

		window.location ='/account';



});

	function signin(){
			formParams = $("#FORM_SIGNIN").serialize();
			
			$('#SPINNER_SIGNIN').html('<img src="/images/ajax-loader-small.gif">'); 
			
			$('#SPINNER_SIGNIN').load("/ajax_doLogin.php",formParams);
		

}


$('#modal_button_sign_in').live("click",function(event){
	
	
	signin();
	

	
	 });

		
		$('#modal_button_register').live("click",function(event){
		
		window.location ='/register';
	 });
	
			


function reloadComments(){


 $("#comment-holder").each(function () {
 	
 			var refstring = this.getAttribute('href');
			
    	var explode = refstring.split("/"); 
			
			var CREFID = explode[1];
			var DREFID = explode[2];
 	
	$(this).html('<img src="/images/ajax-loader-small.gif">'); 
	$(this).load("/ajax_comments.php",{'CREFID':CREFID,'DREFID':DREFID});
			
	
});
}


$('#comment-submit').live("click",function(event){
		alert('asdf');
			
			var FORM  = $('#comment-form');
			formParams = FORM.serialize();
			
			
		$('#comment-spinner').html('<img src="/images/ajax-loader-small.gif">'); 
		$('#comment-spinner').load("/ajax_addComment.php",formParams);
		event.preventDefault();
	
});




////////////////////////////////////////
});
