/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * jQuery validation plug-in 1.7
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
 * http://docs.jquery.com/Plugins/Validation
 *
 * Copyright (c) 2006 - 2008 Jörn Zaefferer
 *
 * $Id: jquery.validate.js 6403 2009-06-17 14:27:16Z joern.zaefferer $
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */



$(document).ready(
    function(){
        
       $('#navCatTabs ul.sf-menu').superfish(
   {
            delay:       500,                            // one second delay on mouseout
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation
            speed:       'fast',                          // faster animation speed
            autoArrows:  true,                           // disable generation of arrow mark-up
            dropShadows: true                            // disable drop shadows
        });

 if($('#slider')[0]){
        $('#slider').nivoSlider({
			pauseTime:5000,
			pauseOnHover:false,
			effect:'random',
			animSpeed:1500,
			startSlide:0,
			directionNav:true,
			controlNav:true,
			keyboardNav:false
			
		});
 }
if($('#create_account')[0]){
   
        $("#create_account").validate({

		rules: {
            gender:"required",
            firstname: {
				required: true,
				minlength: 2
			},
            lastname: {
				required: true,
				minlength: 2
			},
            street_address:{
               required :"true",
               minlength: 5
            },
            city:   "required",
            state:  "required",
            postcode:  {
             required:true,
             minlength:4
            } ,
           zone_country_id:{
               required:true

          },
            telephone:{
                required: true

            },
            dob:{
                required: true,
                dateITA:true
            },
            email_address:{
                required: true,
                email:true
            },
            password:{
                required: true,
                minlength: 5
            },
            confirmation:{
                required: true,
                minlength: 5,
                equalTo: "#password-new"
            }
		},
		messages: {
            gender:"Please selcet your gender",
             firstname:{
                required: "Please enter your firstname.",
                minlength:"must consist of at least 2 characters"
             },
             lastname:{
                required: "Please enter your lastname.",
                minlength:"must consist of at least 2 characters"
             },
            street_address:{
              required:  "Please enter your street address",
              minlength:"must consist of at least 5 characters"
            },
            city:"Please enter your city",
            state:"Please enter your state",
            postcode:{
                required:"Please enter your postcode",
                minlength:"must consist of at least 4 characters"
            },
           zone_country_id:"Please select your country.",
            telephone:{
                required:"Please enter your telephone number"
            },
            dob:"Please enter a valid date.",
            password:{
                required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long"
            },
            confirmation:{
                equired: "Please provide a password",
                minlength: "Your password must be at least 5 characters long",
                equalTo: "Please enter the same password as above"
            },
            email_address: "Please enter a valid email address"

		},
        submitHandler: function(form) {

             form.submit();
             return false;


        },
        errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				//error.insertAfter( element.nextUntil('span'));
                  element.parent().children('span:first').html(error);
            else
               error.insertAfter( element);


		},
        success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");

		}

        });
}
var contact_us;
//When you click on a link with class of poplight and the href starts with a #
	$('a.poplight').click(function(e) {
        e.preventDefault();
       
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size

		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value
       // var old_content = $('#' + popID).html;
		//Fade in the Popup and add close button
        if(contact_us != undefined && contact_us!=''  )
            $('#' + popID).html(contact_us);
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/new/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;

		//Apply Margin to Popup
		$('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});

		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer

		return false;
	});


	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(); //fade them both out
		$('#fade').remove();
		return false;
	});

    $('#askQuestion form').submit(function(){
     
        // alert($(this).serialize());
         //var test='http://localhost/zencart/index.php?main_page=contact_us&action=send&'+$(this).serialize();
        
/*
        $.post(test, function(data) {
           $('#contentMainWrapper').html(data);
          });*/

        $.ajax({
            type: 'POST',
            url: 'http://localhost/zencart/index.php?main_page=contact_us&action=send',
            data: $(this).serialize(),
            success: function(data) {
               contact_us =   $('#askQuestion').html();
                //$('#askQuestion').html("Your message have been sent successfully").fadeIn().css({ 'width': "560px" }).prepend('<a href="#" class="close"><img src="images/new/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');
                $('#askQuestion').html(data);
               
            }
        });

          return false;
          

    });

     $('.addToFav').jFav({msg:'Press "Ctrl + D" or "CMD + D" for MAC or Chrome, to add this page to your bookmarks.'});

     $(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});


    }
);
