$(document).ready(function() {
	if ($.browser.msie && (parseInt($.browser.version) <= 7)) {
		try {
			document.execCommand('BackgroundImageCache', false, true);
		} catch(e){}
	}
	if (window.navigator.userAgent.indexOf('Chrome') !== -1) {
		$('html').css('-webkit-text-size-adjust', 'none');
	}
	$('a[rel="external"]').attr('target', '_blank');
	tab();
	drop();
	home_slider();
	toggle_comm_top();
	toggle_product_box();

$('.drop a').parent().parent().next().slideToggle();

});

function home_slider() {
	if ($('.home-row .col-2').length < 1) return false;
	var slider = $('.home-row .col-2');
	var index = 0,
		length = $('li', slider).length,
		step = 499,
		speed = 15000,
		timer = null;
	var auto_play = function() {
		index++;
		if (index >= length) index = 0;
		$('ul', slider).animate({left:-index*step});
	};
	$('.btn', slider).click(function() {
		auto_play();
	});
	timer = setInterval(auto_play, speed);
}

function toggle_comm_top() {
	if ($('.comm-top').length < 1) return false;
	$('.comm-top .drop').click(function() {
		$('.comm-top .list').slideToggle(200);
		$('.comm-top .drop').toggleClass('drop-active');
	});
}

function toggle_product_box() {
	if ($('.product-box-toggle').length < 1) return false;
	$('.product-box .item').hover(function() {
		toggle_image(this);
	}, function() {
		toggle_image(this);
	});
}

function toggle_image(obj) {
	if ($(obj).is('.active')) return false;
	var icon = $('.icon', obj),
		i = $('.i', obj),
		tmp = null;	    
	tmp = icon.attr('src');
	icon.attr('src', icon.attr('rel')).attr('rel', tmp);
	tmp = i.attr('src');
	i.attr('src', i.attr('rel')).attr('rel', tmp);
}

function tab() {
	$('.tab-title > a').click(function() {
		$(this).addClass('active').siblings('a').removeClass('active');
		$('.tab-content .item').eq($(this).attr('rel')).addClass('active').siblings('.item').removeClass('active');
		return false;
	});
}

function drop() {
	$('.drop a').click(function() {
		if ($(this).is('.active')) {
			$(this).removeClass('active');
		} else {
			$(this).addClass('active');
		}

		$(this).parent().parent().next().slideToggle();

		return false;
	});
}
