jQuery(function($) {
	
	$('#navigation ul li').hover(function(){ 
		$(this).find('ul.sub-menu:eq(0)').stop(true,true).fadeIn();
		$(this).find('a:eq(0)').addClass('hover');
		$(this).parent().find('li.home a:eq(0)').removeClass('hover');
	 },
	 function(){  
		$(this).find('ul.sub-menu').fadeOut();
		$(this).find('a:eq(0)').removeClass('hover');
 	});


 	$('.blink').
    focus(function() {
        if(this.title==this.value) {
            this.value = '';
        }
    }).
    blur(function(){
        if(this.value=='') {
            this.value = this.title;
        }
    });

    $('.blog-page .comment-box .field').focus(function() {
        $(this).css("background-color","#ffff9c");
    }).blur(function(){
        $(this).css("background-color","#ffffff");
    });

    
	// Slider Carousel
	$(".slider-carousel ul").jcarousel({
		scroll:1,
		auto:sliderSpeed,
		wrap:"both",
        itemFirstInCallback: mycarousel_itemFirstInCallback,
        initCallback: mycarousel_initCallback,
        start: 1
		
	});

	// Tabs
	$('.tabs').each(function() {
		$(this).find('.tab-item:eq(0)').fadeIn();
	})
	$('.bottom-tabs').find('.item:eq(0)').fadeIn();

	$('.tabs .tab-nav ul li a, .bottom-tabs .tab-nav ul li a').live('click', function() {
	     if (!$(this).hasClass('active')) {
	     	if ($(this).hasParent('.tabs .tab-nav')) {
	     		var tabIndex = $('.tabs .tab-nav ul li a').index(this);
	     	} else {
	     		var tabIndex = $('.bottom-tabs .tab-nav ul li a').index(this);
	     	}
	        $('.tabs .tab-content .tab-item, .bottom-tabs .tab-content .item').hide();
	        $('.tabs .tab-nav ul li a, .bottom-tabs .tab-nav ul li a').removeClass('active');
	        $(this).addClass('active');
	        $('.tabs .tab-content .tab-item:eq('+tabIndex+')').fadeIn();
	        $('.bottom-tabs .tab-content .item:eq('+tabIndex+')').fadeIn();
	    };
	    return false;

	});


	// Location
	$(window).load(function() {
		setTimeout(function() {
			$('.locations').each(function() {
				$(this).find('.place').not(':first').hide();
			})
		}, 1000);
	});
	$('.locations .location-nav li a').click(function() {
	    if ($(this).hasClass('active')) {
	    } else {
	        var tabIndex = $('.locations .location-nav li a').index(this) ;
	        $('.locations .place').hide();
	        $('.locations .location-nav li a').removeClass('active');
	        $(this).addClass('active');
	        $('.locations .place:eq('+tabIndex+')').fadeIn();
	    };
	    return false;

	});

	
	$('ul.acc li a.first').live('click',function(e) {
		if (!$(e.target).is("span")) {
			$(this).next().slideToggle();
			$(this).toggleClass('active');
			return false;
		}
	});

	function mycarousel_initCallback(carousel) {
	    $('.slider-nav a').bind('click', function() {
	        carousel.scroll($.jcarousel.intval($(this).attr('rel')));
	        return false;
	    });	        
	};
		
	function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
		$('.slider-nav a').removeClass('active').find('.overlay').show();
		$('.slider-nav a').eq(idx-1).addClass('active').find('.overlay').hide();
	};

	$('#navigation li').each(function() {
		if ($(this).text()=='Home') {
			$(this).addClass('home');
		}
	});

	$('.footer-nav a').unwrap();
	$('body.home .boxes .box:first').addClass('first');

	$('.twitter-feed:last li:first').css('background', 'transparent');

	$('.buttons').each(function() {
		if (!$(this).next('.buttons').length) {
			$(this).after('<div class="cl"></div>');
		}
	});

	$('.cols').each(function() {
		$('.col:last', this).addClass('last');
	});
	$('.cols > p').remove();

	$('.paganation').wrapInner('<ul />');
	$('.paganation a, .paganation span').wrap('<li />');
	$('.paganation li').unwrap();

	$('.widget_nav_menu li a').hover(function() {
		$(this).parent().toggleClass('sidebar-menu-hover');
	});
	$('.widget_nav_menu li:last').addClass('last');

	$('.discussions > .replays > .comment-box').css('background', '#FCFDE0');

	$('.acc-content > br').remove();

	$('.page-template-page-lines-php .inner-content > p').each(function() {
		$(this).text($.trim($(this).text()));
		$(this).not(':empty').addClass('product-description');
	});

	$('.tab-nav').each(function() {
		$(this).find('a:first').addClass('active');
	});

	$('ul.acc').each(function() {
		$(this).find('> li > a').addClass('first').wrapInner('<span />');
		$(this).find('ul').addClass('dd');
	});

	$('a.iframe').fancybox({
		'width':700,
		'height':700
	});

	$.fn.hasParent = function(objs) {
		objs = $(objs); var found = false;
		$(this[0]).parents().andSelf().each(function() {
			if ($.inArray(this, objs) != -1) {
				found = true;
				return false;
			}
		});
		return found;
	}

	if ($('.locations').length) {
		$('.content-entry > p, .content-entry > div > p').addClass('product-description');
		$('body').addClass('template-page');
	}

	$('.bottom-tabs .item h5').not(':first').css('margin-top', '25px');

	$('.featured-product-theme-widget ul').addClass('mini-list');

	if ($('body.page-template-page-lines-php, body.page-template-page-brand-php,\
	 body.page-template-page-special-php, body.page-template-page-products-php, body.single-pt_product').length) {
	 	$('#navigation > ul > li > a').each(function() {
	 		if ($(this).text().toLowerCase().indexOf('products')!=-1) {
	 			$(this).parents('li').addClass('current-menu-item');
	 		}
	 	});
	 }

});
