$("document").ready(function(){
/* BIG SLIDER */
  $("#slider").SexySlider({
    width      : 556,
    height     : 290,
    delay      : 4000,
    strips     : 15,
    autopause  : false,
    titleStyle : '',
    control    : '#control',
    effect     : 'wave'
  });
/* END BIG SLIDER   */

/*TOP NAV STYLING*/
	$('#nav_top ul.level-0 li a').last().css('border','none');
/*END TOP NAV STYLING*/

/* PREVENT DEFAULT CLICK ON 'PRODUCTS' NAVIGATION ITEM 			 */
	$('#nav_top ul.level-0.sub-section li a').eq(2).click(function(event){event.preventDefault()});

/*	AUTOFILL FORMS 			 */
//	autoFill('#newsletter-name','Name');
//	autoFill('#newsletter-email','Email');
	autoFill('#search #search-form','Live Search:')
	


/* NAVIGATION */
	ddsmoothmenu.init({
		mainmenuid: "nav_top", //menu DIV id
		orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'ddsmoothmenu', //class added to menu's outer DIV
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"],
	});	
/* END NAVIGATION */
if($('.accordion'))
	{
		jQuery('.accordion').accordion({
			active: false, 
			header: 'h4',
			autoheight: false,
			alwaysOpen: false
		});
	
	}
/* LOGIN  TOOLBAR */
	$('#toolbar-toggler').click(function() {
	  $(this).toggleClass('expanded');
	  $('#toolbar').animate({
	    height: ['toggle', 'swing']
	  }, 200, 'easeOutBounce');
	});
	
	
	/* LANGUAGE TOOLBAR */
	$('#nav_lang li a').hover(function() {
		//$('#nav_lang li.active').appendTo($('#nav_lang'));
		$(this).parent().parent().toggleClass('show'); 
	});
	


	/* LOGIN */
	$('.error').hide();	
	// When the form is submitted
	$("form#login-form").submit(function(){  
	    $('.error').hide();
	      // validate and process form here
	      $('.error').hide();
		$('label#username,label#password').show();      
	  	  var name = $("#username input").val();
	  		if (name == "") {
	        $("label#username_error").show();
			$('label#username').hide();
	        $("#username input").focus();
	        return false;
	      }
	  		var password = $("#password input").val();
	  		if (password == "") {
	        $("label#password_error").show();
			$('label#password').hide();
	        $("#password input").focus();
	        return false;
	      }
	
	// Hide 'Submit' Button
	$('#submit-login').hide();
	
	// Show Gif Spinning Rotator
	$('#ajax_loading').show();
	
	// 'this' refers to the current submitted form
	var str = $(this).serialize();  
	// -- Start AJAX Call --
	
	$.ajax({
	    type: "POST",
	    url: base_url_lang+"login",  // Send the login info to this page
	    data: str,
	    success: function(msg){  
		$("#toolbar").ajaxComplete(function(event, request, settings){  
		

			
			 if(msg == 'OK') // LOGIN OK?
			 {
			
			 $(this).html(login_response); // Refers to 'status'
			
			// After 3 seconds redirect the
//			setTimeout('go_to_private_page()', 3000);
			go_to_private_page();
			 }
			 else // ERROR?
			 {
				 var login_response = msg;
				 $('label#username').hide();
				 $('#invalid_access').show();
				 // Show 'Submit' Button
				$('#submit-login').show();
				
				// Hide Gif Spinning Rotator
				$('#ajax_loading').hide();  				 
			 }  
		
		 });  
	
	 }  
	});  
	// -- End AJAX Call --
	return false;	
	}); // end submit event
	

	/* AUTOCOMPLETE */
	$("#search-form").autocomplete(search_tearms, {
		width: 282,
		selectFirst: false,
		matchContains: true,
		formatItem: function(row, i, max) {
			return row.title;
		}
	}).result(function(event, item) {
		if(item.tbl=='products_categories')
		{
	  		location.href = base_url_lang+'products/'+item.slug;
		}
	  	else if(item.tbl=='products')
		{
	  		location.href = base_url_lang+'product/'+item.slug;		
		}
	  	else
	  	{
	  		if(item.slug=='Home')
	  			location.href = base_url_lang;	  	
	  		else if(item.slug=='Contact-Us' && cilang=='en/' )
	  			location.href = base_url_lang+'contact-us';	  	
	  		else if(item.slug=='Contact-Us' && cilang=='es/' )
	  			location.href = base_url_lang+'contacto';	  	
	  		else
	  			location.href = base_url_lang+item.slug;	  	
	  		
	  	}
	  	
});
	

	function log(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	
	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}
		

});

function go_to_private_page()
{
	window.location = base_url_lang+'Standard-Parking-Corporation'; // Members Area
}
/* FUNCTION AUTOFILL FORMS*/
function autoFill(id, v){
	$(id).css({ color: "#b2adad" }).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("").css({ color: "#333" });
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).css({ color: "#b2adad" }).val(v);
		}
	});
}

/* PHPLIST SUBMITION */
if($('.widget#phplist .success'))
{
	setTimeout(function(){
		$('.widget#phplist .success').fadeOut("slow");
	},8000);}

