jQuery.noConflict();
    
jQuery(document).ready(function(){
								
	jQuery('#product-menu-wrapper ul').each(function(){
													 jQuery(this).append('<li class="last"></li>');
													 });
	
	if(jQuery('.obj_imp').length>0){
	var obj = jQuery('.obj_imp');
	var obj_add = obj.attr('href');
	
	var wrapper = '<div class="swf-obj-wrapper"></div>';
	
	obj.parent().append(wrapper);
	
	var swfReplace = jQuery.flash.create(
	{
		swf: obj_add,
		height: 750,
		width: 947
	}
	);
	
	jQuery('.swf-obj-wrapper').html(swfReplace);
	
	}

    jQuery('#header .menu ul li').each(function() {
        if(jQuery(this).find('ul').length != 0)
            jQuery('> a', this).addClass('has_submenu');
    });
	
	jQuery('#header .menu li').each(function() {	
            submenu = jQuery('> .sub-menu', this);
			submenu.css({display:"none"});
	});
    
    jQuery('#header .menu li').hover(function() {	
            submenu = jQuery('> .sub-menu', this);
            submenu.stop().css({overflow:"hidden", height:"auto", display:"none"}).slideDown(300, function()
            {
                jQuery(this).css({overflow:"visible"});
            });	
		},
		function() {	
            submenu = jQuery('> .sub-menu', this);
            top_distance = jQuery(this).parent().is('#header .menu') ? '13px' : '0';
            submenu.stop().css({overflow:"hidden", height:"auto", display:"block", top:top_distance}).slideUp(300, function()
            {	
                jQuery(this).css({display:"none"});
            });
        }
    );
                         
	jQuery(".toggle_content").hide(); 

	jQuery(".toggle").toggle(function(){
		jQuery(this).addClass("active");
		}, function () {
		jQuery(this).removeClass("active");
	});
	
	jQuery(".toggle").click(function(){
		jQuery(this).next(".toggle_content").slideToggle();

	});
    
    jQuery("ul.tabs").tabs("div.panes > div");
    
    jQuery('form#contactform').submit(function() {
        jQuery('.loaderIcon', this).css('display', 'inline-block');
        jQuery('input, textarea', this).removeClass('invalid');
        
        var name = jQuery('input#cfname', this).val();
        var email = jQuery('input#cfemail', this).val();
        //var website = jQuery('input#cfwebsite', this).val();
        var phone = jQuery('input#cfphone', this).val();
		var vehicle = jQuery('input#cfvehicle', this).val();
		var year = jQuery('input#cfyear', this).val();
		var model = jQuery('input#cfmodel', this).val();
        var message = jQuery('textarea#cfmessage', this).val();
        var submit_url = jQuery('input#submit_url', this).val();
        var contactform = jQuery(this);

        jQuery.ajax({
            type: 'post',
            url: submit_url,
            data: 'action=iwak_ajax_action&type=contact&cfname=' + name + '&cfemail=' + email + '&cfphone=' + phone + '&cfvehicle=' + vehicle + '&cfyear=' + year + '&cfmodel=' + model + '&cfmessage=' + message,
            success: function(results) {
                jQuery('.loaderIcon', contactform).css('display', 'none');
                if(results) {
                    if(results.charAt(0) == 1) jQuery('input#cfname', contactform).addClass('invalid');
                    if(results.charAt(1) == 1) jQuery('input#cfemail', contactform).addClass('invalid');
					if(results.charAt(2) == 1) jQuery('input#cfphone', contactform).addClass('invalid');
                    if(results.charAt(3) == 1) jQuery('textarea#cfmessage', contactform).addClass('invalid');
                } else {
                    contactform.slideUp();
                    jQuery("<p class='thanyou hidden'>Your message has been sent, thank you!</p>").insertAfter(contactform).fadeIn();
                }
            }
        }); // end ajax
        
        // Prevent form action being triggered
        return false;
    });
    
    jQuery(".testimonial li:not(.active)").each(function() {
        jQuery(this).css({'position':'absolute','visibility':'hidden','display':'block'});
    });
    
    jQuery(".testimonial-wrapper span.next").click(function() {
        var container_tm = jQuery(this).parent().prev('.testimonial');
        var current_tm = container_tm.find('li.active');
        if(!current_tm)
            return;
            
        var curr_height = current_tm.height();
        var next_tm = current_tm.next('li');
        if(next_tm.length == 0)
            next_tm = jQuery('li:first', container_tm);
            
        var next_height = next_tm.height();
        
        current_tm.fadeOut().removeClass('active');
        next_tm.css('visibility', 'visible').fadeIn().addClass('active');
        container_tm.height(curr_height).animate({height:next_height});
    });
    
    jQuery(".testimonial-wrapper span.prev").click(function() {
        var container_tm = jQuery(this).parent().prev('.testimonial');
        var current_tm = container_tm.find('li.active');
        if(!current_tm)
            return;
            
        var curr_height = current_tm.height();
        var prev_tm = current_tm.prev('li');
        if(prev_tm.length == 0)
            prev_tm = jQuery('li:last', container_tm);
            
        var prev_height = prev_tm.height();
        
        current_tm.fadeOut().removeClass('active')
        prev_tm.css('visibility', 'visible').fadeIn().addClass('active');
        container_tm.height(curr_height).animate({height:prev_height});
    });
    /*
    jQuery('#portfolio .thumblink').hover(function() {
        jQuery('.thumbnail', this).fadeTo(500, 0.4);
        //jQuery('.extra', this).fadeTo(500, 0.8);  // IE7 opacity bug
    },
    function() {
        jQuery('.thumbnail', this).fadeTo(500, 1);
        //jQuery('.extra', this).fadeTo(500, 1);    // IE opacity bug
    }
    );*/
    
    // work hover animation
    jQuery('.works .portfolio-entry, .works .post-entry').each(function(settings) {
        settings = {'durationIn': 180, 'durationOut': 350, 'easingIn': 'easeOutQuad', 'easingOut': 'easeInCirc'};
        jQuery(this).hover(function() {
            h = jQuery('.entry-title', this).outerHeight();
            jQuery('.entry-title', this).stop().css({top: '-' + h + 'px', visibility: 'visible'}).animate({top:'0'}, settings.durationIn, settings.easingIn);
            jQuery('.more-link', this).animate({bottom:'-10px'}, settings.durationIn, settings.easingIn);
            if(!(jQuery.browser.msie && jQuery.browser.version < 9)) // exclude ie8- because of their poor support for png
                jQuery('.extra', this).delay(100).fadeIn('slow');
        }, function() {
            h = jQuery('.entry-title', this).outerHeight();
            jQuery('.entry-title', this).stop().animate({top: '-' + h + 'px'}, settings.durationOut, settings.easingOut);
            jQuery('.more-link', this).animate({bottom:'-40px'}, settings.durationOut, settings.easingOut);
            if(!(jQuery.browser.msie && jQuery.browser.version < 9)) // exclude ie8- because of their poor support for png
                jQuery('.extra', this).fadeOut();
        });
    });
    
    /* height animation doesn't compatible to chrome
    jQuery('#portfolio').height(jQuery('#portfolio').height());
    jQuery('#portfolio-list').resize(function() {
        filter_height = jQuery('#portfolio-filter').outerHeight(true);
        list_height = jQuery('#portfolio-list').outerHeight();
        jQuery('#portfolio').animate({height: filter_height + list_height + 'px'});
    });*/
    
    // menu hover animation
    focusing_icon = jQuery('#menu-wrapper .icon');
    active_menu = jQuery('#main-nav li.current-menu-item');
    if(active_menu.length) {
        var parent = active_menu.parents('#main-nav > li');
        if(parent.length) active_menu = parent;
        p = active_menu.position();
        w = active_menu.width();
        start = p.left + w - (w/2)-15;
    } else 
        start = -5;
        
    focusing_icon.css({left:start}).show();
    
    jQuery('#main-nav > li').hover(function() {
        p = jQuery(this).position();
        w = jQuery(this).width();
        end = p.left + w - (w/2)-15;
        focusing_icon.stop().animate({left:end}, 'slow', 'easeOutCirc');
    }, function() {
        focusing_icon.stop().animate({left:start}, 'slow');
    }
    );

    // belt animation (max one belt per page)
    belt = jQuery('.works ul');
    belt_slots = jQuery('li', belt).length;
    left_slots = belt_slots - 4;
    jQuery('.works .more').click(function() {
        duration = 'slow';
        easing = 'easeOutQuad';
        if(left_slots > 0) {
            belt.animate({marginLeft: '-=960px'}, duration, easing);
            left_slots -= 4;
        }
        else if(belt_slots > 4){
            belt.animate({marginLeft: '0px'}, duration, easing);
            left_slots = belt_slots - 4;
        }
    }
    );
    
    jQuery.fn.rotate = function(degree) {
        var target = jQuery(this);
        target.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});  
        target.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});                      
    }
    
    jQuery(".panel .more").mouseenter(function() {
        var target = jQuery('a', this);
        if(jQuery.browser.msie) {
            return;
        }
        degree = 0;
        rolling = setInterval(function() {
            degree -= 5;
            if(degree <= -185)
                clearInterval(rolling);
            else
                target.rotate(degree);
        },10);
    }
    );

    jQuery('.post.entry .thumbnail, .post-entry .thumbnail').hover(function() {
        jQuery(this).fadeTo(180, 0.5, 'easeOutQuad');
    }, function() {
        jQuery(this).fadeTo(350, 1, 'easeInCirc');
    }
    );
	
/* begin scrolltop control */
jQuery(function(){
   sh = jQuery(window).height() / 2;
   xh = jQuery(document).height() /2 - sh;
});	

var scrolltotop={
	
	setting: {startline:200, scrollto: 0, scrollduration:1000, fadeduration:[200, 50]},
	controlHTML: '<span class="scroll_up"></span>',
	controlattrs: {offsetx:5, offsety:5}, 
	anchorkeyword: '#top',
	state: {isvisible:false, shouldvisible:false},

	scrollup:function(){
		if (!this.cssfixedsupport) 
			this.$control.css({opacity:0}) 
		var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
		if (typeof dest=="string" && jQuery('#'+dest).length==1) 
			dest=jQuery('#'+dest).offset().top
		else
			dest=0
		this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
	},

	keepfixed:function(){
		var $window=jQuery(window)
		var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
		var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
		this.$control.css({left:controlx+'px', top:controly+'px'})
		
	
	},

	togglecontrol:function(){
		var scrolltop=jQuery(window).scrollTop()
		if (!this.cssfixedsupport)
			this.keepfixed()
		this.state.shouldvisible=(scrolltop>=xh)? true : false
		if (this.state.shouldvisible && !this.state.isvisible){
			this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
			this.state.isvisible=true
		}
		else if (this.state.shouldvisible==false && this.state.isvisible){
			this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
			this.state.isvisible=false
		}
	},
	
	init:function(){
		jQuery(document).ready(function(){
			var mainobj=scrolltotop
			var iebrws=document.all
			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
			mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? jQuery('html') : jQuery('body')) : jQuery('html,body')
			mainobj.$control=jQuery('<div id="topcontrol"><span class="scroll_up"></span></div>')
				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
				.attr({title:'Scroll Back to Top'})
				.click(function(){mainobj.scrollup(); return false})
				.appendTo('body')
			if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
				mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
			mainobj.togglecontrol()
			jQuery('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
				mainobj.scrollup()
				return false
			})
			jQuery(window).bind('scroll resize', function(e){
				mainobj.togglecontrol()
			})
		})
	}
}

scrolltotop.init()
/* end scrolltop control */

	jQuery.fn.mojo_image_preloader = function(options) 
	{
		var defaults = 
		{
			repeatedCheck: 500,
			fadeInSpeed: 1000,
			delay:600,
			callback: ''
		};
		
		var options = jQuery.extend(defaults, options);
		
		return this.each(function()
		{
			var imageContainer = jQuery(this),
				images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
				imagesToLoad = images.length;				
				
				imageContainer.operations =
				{	
					preload: function()
					{	
						var stopPreloading = true;
						
						images.each(function(i, event)
						{	
							var image = jQuery(this);
							
							
							if(event.complete == true)
							{	
								imageContainer.operations.showImage(image);
							}
							else
							{
								image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
							}
							
						});
						
						return this;
					},
					
					showImage: function(image)
					{	
						imagesToLoad --;
						if(image.data.currentImage != undefined) { image = image.data.currentImage;}
												
						if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
												 
						if(imagesToLoad == 0)
						{
							if(options.delay > 0)
							{
								images.each(function(i, event)
								{	
									var image = jQuery(this);
									setTimeout(function()
									{	
										image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
									},
									options.delay*(i+1));
								});
								
								if(options.callback != '')
								{
									setTimeout(options.callback, options.delay*images.length);
								}
							}
							else if(options.callback != '')
							{
								(options.callback)();
							}
							
						}
						
					}

				};
				
				imageContainer.operations.preload();
		});
		
	}

	jQuery.fn.mojo_fade_slider= function(options) 
	{
		var defaults = 
		{
			slides: '>div',				// wich element inside the container should serve as slide
			animationSpeed: 900,		// animation duration
			autorotation: true,			// autorotation true or false?
			autorotationSpeed:3,		// duration between autorotation switch in Seconds
			appendControlls: '',
			backgroundOpacity:0.8		// opacity for background
		};
		
		var options = jQuery.extend(defaults, options);
		
		
		
		return this.each(function()
		{
			var slideWrapper 	= jQuery(this),								
				slides			= slideWrapper.find(options.slides).css({display:'none',zIndex:0}),
				slideCount 	= slides.length,
				currentSlideNumber = 0,
				interval,
				current_class = 'active_item',
				controlls = '',
				skipSwitch = true;
				
				slideWrapper.find(options.slides+':first').addClass('active_item');
				
				//slides.find('.feature_excerpt').css('opacity',options.backgroundOpacity);
				
				slideWrapper.methods = {
				
					init: function()
					{
						slides.filter(':eq(0)').css({zIndex:2, display:'block'});
						
						if(slideCount <= 1)
						{
							slideWrapper.mojo_image_preloader({delay:200});
						}
						else
						{
							slideWrapper.mojo_image_preloader({callback:slideWrapper.methods.preloadingDone, delay:200});
							
							if (options.appendControlls)
							{
								controlls = jQuery('<div></div>').addClass('slidecontrolls').css({position:'absolute'}).appendTo(options.appendControlls);
								slides.each(function(i)
								{	
									var controller = jQuery('<span class="ie6fix '+current_class+'"></span>').appendTo(controlls);
									controller.bind('click', {currentSlideNumber: i}, slideWrapper.methods.switchSlide);
									current_class = "";
								});	
							}
						}						
					},
					
					preloadingDone: function()
					{
						skipSwitch = false;
						
						if(options.autorotation)
						{
							slideWrapper.methods.autorotate();
						}
					},
					
					switchSlide: function(passed)
					{	
						var noAction = false;
						
						if(passed != undefined && !skipSwitch)
						{	
						
							if(currentSlideNumber != passed.data.currentSlideNumber)
							{	
								currentSlideNumber = passed.data.currentSlideNumber;
							}
							else
							{
								noAction = true;
							}
						}
						
						if(passed != undefined)
						{	
							clearInterval(interval);
						}
						
						if(!skipSwitch && noAction == false)
						{	
							skipSwitch = true;
							var currentSlide = slides.filter(':visible'),
							caption = currentSlide.find('.feature_excerpt'),
							nextSlide = slides.filter(':eq('+currentSlideNumber+')'),
							next_caption = nextSlide.find('.feature_excerpt').css({bottom:'-50px'});
							
								if(options.appendControlls)
								{	
									controlls.find('.active_item').removeClass('active_item');
									controlls.find('span:eq('+currentSlideNumber+')').addClass('active_item');									
								}
								
							currentSlide.css({zIndex:4});
							nextSlide.css({zIndex:2, display:'block'});
							
							if(caption.length>0){
							
							caption.animate({bottom:'-50px'},function(){
							currentSlide.fadeOut(options.animationSpeed, function()
							{
								currentSlide.css({zIndex:0, display:"none"});
								skipSwitch = false;
								if(next_caption.length>0){
									next_caption.animate({bottom:'0px'});
								}
								
							});
							
																  });
																  }else{
																	  
																	currentSlide.fadeOut(options.animationSpeed, function()
							{
								currentSlide.css({zIndex:0, display:"none"});
								skipSwitch = false;
								if(next_caption.length>0){
									next_caption.animate({bottom:'0px'});
								}
							});
																	  
																  }
						}
					},
					
					autorotate: function()
					{	
						interval = setInterval(function()
						{ 	
							currentSlideNumber ++;
							if(currentSlideNumber == slideCount) currentSlideNumber = 0;
							
							slideWrapper.methods.switchSlide();
						},
						(parseInt(options.autorotationSpeed) * 1000));
					}
				
				};
				
				slideWrapper.methods.init();
		});
		
	}
    
});



