/*
 * jQuery.appear
 * http://code.google.com/p/jquery-appear/
 *
 * Copyright (c) 2009 Michael Hixson
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
*/
(function($){$.fn.appear=function(f,o){var s=$.extend({one:true},o);return this.each(function(){var t=$(this);t.appeared=false;if(!f){t.trigger('appear',s.data);return;}var w=$(window);var c=function(){if(!t.is(':visible')){t.appeared=false;return;}var a=w.scrollLeft();var b=w.scrollTop();var o=t.offset();var x=o.left;var y=o.top;if(y+t.height()>=b&&y<=b+w.height()&&x+t.width()>=a&&x<=a+w.width()){if(!t.appeared)t.trigger('appear',s.data);}else{t.appeared=false;}};var m=function(){t.appeared=true;if(s.one){w.unbind('scroll',c);var i=$.inArray(c,$.fn.appear.checks);if(i>=0)$.fn.appear.checks.splice(i,1);}f.apply(this,arguments);};if(s.one)t.one('appear',s.data,m);else t.bind('appear',s.data,m);w.scroll(c);$.fn.appear.checks.push(c);(c)();});};$.extend($.fn.appear,{checks:[],timeout:null,checkAll:function(){var l=$.fn.appear.checks.length;if(l>0)while(l--)($.fn.appear.checks[l])();},run:function(){if($.fn.appear.timeout)clearTimeout($.fn.appear.timeout);$.fn.appear.timeout=setTimeout($.fn.appear.checkAll,20);}});$.each(['append','prepend','after','before','attr','removeAttr','addClass','removeClass','toggleClass','remove','css','show','hide'],function(i,n){var u=$.fn[n];if(u){$.fn[n]=function(){var r=u.apply(this,arguments);$.fn.appear.run();return r;}}});})(jQuery);

/*Plugin: jQuery Parallax Version 1.1.3*/
!function(n){var t=n(window),e=t.height();t.resize(function(){e=t.height()}),n.fn.parallax=function(o,i,r){function u(){var r=t.scrollTop();a.each(function(){var t=n(this),u=t.offset().top,c=h(t);r>u+c||u>r+e||a.css("backgroundPosition",o+" "+Math.round((l-r)*i)+"px")})}var h,l,a=n(this);a.each(function(){l=a.offset().top}),h=r?function(n){return n.outerHeight(!0)}:function(n){return n.height()},(arguments.length<1||null===o)&&(o="50%"),(arguments.length<2||null===i)&&(i=.1),(arguments.length<3||null===r)&&(r=!0),t.bind("scroll",u).resize(u),u()}}(jQuery);
$(document).ready(function(){
    //=====> Animated
    $('.with-animated .animated').appear(function() {
       var elem = $(this);
       var animation = elem.data('animation');
       if ( !elem.hasClass('visible') ) {
        var animationDelay = elem.data('animation-delay');
        if ( animationDelay ) {
     
         setTimeout(function(){
          elem.addClass( animation + " visible" );
          elem.removeClass('hiding');
         }, animationDelay);
     
        } else {
         elem.addClass( animation + " visible" );
         elem.removeClass('hiding');
        }
       }
      });
	//-----------> Parallax 
	if ( $.isFunction($.fn.parallax) ) {
		$('.ave_parallax1').parallax("50%", 0.1);
		$('.ave_parallax2').parallax("50%", 0.2);
		$('.ave_parallax3').parallax("50%", 0.3);
		$('.ave_parallax4').parallax("50%", 0.4);
		$('.ave_parallax5').parallax("50%", 0.5);
		$('.ave_parallax6').parallax("50%", 0.6);
		$('.ave_parallax7').parallax("50%", 0.7);
		$('.ave_parallax8').parallax("50%", 0.8);
		$('.ave_parallax9').parallax("50%", 0.9);
	}
});
/*End Plugin: jQuery Parallax Version 1.1.3*/
function reload_captcha(id) {
        var obj = document.getElementById(id);
    if(obj){
        var src ='index.php?route=avethemes/common/captcha';
        var date =new Date();
        obj.src = src + '&time=' + date.getTime();
        return false;
    }
}
$(document).ready(function() {
	//----=====> Single Product Number Of Items
    $('body').on('click touchstart', '.quantity_controll',function(e) {
        var $button = $(this);
        var oldValue = $button.siblings('.input-text').val();
        var newVal;
        
        if ($button.hasClass('plus')) {
            newVal = parseFloat(oldValue) + 1;
        } else {
            if (oldValue > 1) {
                newVal = parseFloat(oldValue) - 1;
                
            } else {
                newVal = 1;
            }
        }
        $button.siblings('.input-text').val(newVal);
    });
	//Popup Quickview
    $('body.with-quickview').on('click touchstart', '.btn-quick-view',function(e) {
            e.preventDefault();
            var element = this;
            var href = 'index.php?route=avethemes/ave_quickview&product_id='+$(element).attr('data-id');
    
            $('#modal-box').remove(); 
            
            var title = $(element).attr('data-title');
            if (title == ''||title == null) {
                title = $(element).attr('title');
            }
            if (title == ''||title == null) {
                title = $(element).text();
            }
            $.ajax({
                url:href,
                type: 'get',
                dataType: 'html',
                success: function(data) {	
                    html  = '<div id="modal-box" class="modal-box modal fade">';
                    html += '  <div class="modal-dialog modal-lg">';
                    html += '    <div class="modal-content">';
                    html += '      <div class="modal-header">'; 
                    html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
                    html += '        <h4 class="modal-title">' + title + '&nbsp;</h4>';
                    html += '      </div>';
                    html += '      <div class="modal-body modal-html">' + data + '</div>';	
                    html += '    </div';
                    html += '  </div>';
                    html += '</div>';	
                    $('body').append(html);				
                    $('#modal-box').modal('show');
                }
            });
        
    });
	//Popup agree policy
    $(document).delegate('.agree,.colorbox,.modalbox', 'click touchstart', function(e) {
            e.preventDefault();
            $('#modal-box').remove(); 
        var element = this;
        var href = $(element).attr('href');
        
        var title = $(element).attr('data-title');
            if (title == ''||title == null) {
                title = $(element).attr('title');
            }
            if (title == ''||title == null) {
                title = $(element).text();
            }
        
        if($(element).hasClass('colorbox')||$(element).hasClass('modalbox')||$(element).hasClass('agree')){
            type='html';
        }else{
            type='iframe';
        }
        if(type=='iframe'){
            html  = '<div id="modal-box" class="modal-box modal fade">';
            html += '  <div class="modal-dialog modal-lg">';
            html += '    <div class="modal-content">';
            html += '      <div class="modal-header">'; 
            html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
            html += '        <h4 class="modal-title">' + title + '&nbsp;</h4>';
            html += '      </div>';
            html += '      <div class="modal-body modal-iframe"><iframe frameborder="0" src="'+href+'"></iframe></div>';
            html += '    </div';
            html += '  </div>';
            html += '</div>';	
            $('body').append(html);				
            $('#modal-box').modal('show');		
        }else{
            $.ajax({
                url:href,
                type: 'get',
                dataType: 'html',
                success: function(data) {	
                    html  = '<div id="modal-box" class="modal-box modal fade">';
                    html += '  <div class="modal-dialog modal-lg">';
                    html += '    <div class="modal-content">';
                    html += '      <div class="modal-header">'; 
                    html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
                    html += '        <h4 class="modal-title">' + title + '&nbsp;</h4>';
                    html += '      </div>';
                    html += '      <div class="modal-body modal-html">' + data + '</div>';	
                    html += '    </div';
                    html += '  </div>';
                    html += '</div>';	
                    $('body').append(html);				
                    $('#modal-box').modal('show');
                }
            });		
        }
    
    });
    $('.modal-header .close').on('click touchstart', function() {		
        $('.modal-backdrop').remove(); 
        $('body').removeClass('modal-open'); 
    });
    $(".quantity_controll").on("click touchstart", function() {
			
			var $button = $(this);
			var oldValue = $button.siblings('.input-text').val();
			var newVal;
			
			if ($button.hasClass('plus')) {
				newVal = parseFloat(oldValue) + 1;
			} else {
				if (oldValue > 1) {
			  		newVal = parseFloat(oldValue) - 1;
					
				} else {
			  		newVal = 1;
				}
			}
			$button.siblings('.input-text').val(newVal);
		});
});
function activeObj(obj,val) {
	$('.'+obj).hide();
	$('.'+obj+'.otp-'+val).show();
}

/*Custom Javascript*/