// jQuery
$(function() {

	// External Linx In New Window
	$('a.external').click(function() {
		window.open(this.href);
		return false;
	});
	
	$('textarea').css('resize', 'none');

/*	// Automatic Highslide Effect For Copied Descriptions From Kyosho's Website
	var descriptive_images = $('#tab_description table td.subimg img');
	if ( descriptive_images.length >= 1 ) {
		for (var i = 0; i < descriptive_images.length; i++) {
			var image_link = $(descriptive_images[i]).attr('src');
			var image_alt = ( $(descriptive_images[i]).attr('alt') ) ? $(descriptive_images[i]).attr('alt') : 'RC car detail';
			var highslided = '<a class="highslide" href="' + image_link + '" title="" onclick="return hs.expand(this)"><img src="' + image_link + '" title="" alt="' + image_alt + '" /></a>';
			$(descriptive_images[i]).replaceWith(highslided);
		}
	}	*/

	// Cart Module Animation
	$('#module_cart').hover(function() {
		$('#module_cart .middle').stop(true, true).slideToggle('fast');
	});
	$('#module_cart').mouseleave(function() {
		$('#module_cart .middle').stop(true, true).slideUp('fast');
	});

});

// section moved from 'header.tpl'
function getURLVar(urlVarName) {
	var urlHalves = String(document.location).toLowerCase().split('?');
	var urlVarValue = '';
	
	if (urlHalves[1]) {
		var urlVars = urlHalves[1].split('&');

		for (var i = 0; i <= (urlVars.length); i++) {
			if (urlVars[i]) {
				var urlVarPair = urlVars[i].split('=');
				
				if (urlVarPair[0] && urlVarPair[0] == urlVarName.toLowerCase()) {
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	
	return urlVarValue;
}

$(function() { // line not present in 'header.tpl'
	$(document).ready(function() {
		route = getURLVar('route');
		
		if (!route) {
			$('#tab_home').addClass('selected');
		} else {
			part = route.split('/');
			
			if (route == 'common/home') {
				$('#tab_home').addClass('selected');
			} else if (route == 'account/login') {
				$('#tab_login').addClass('selected');	
			} else if (part[0] == 'account') {
				$('#tab_account').addClass('selected');
			} else if (route == 'checkout/cart') {
				$('#tab_cart').addClass('selected');
			} else if (part[0] == 'checkout') {
				$('#tab_checkout').addClass('selected');
			} else {
				$('#tab_home').addClass('selected');
			}
		}
	});
}); // line not present in 'header.tpl'

$(function() { // line not present in header.tpl
	$('.switcher').bind('click', function() {
		$(this).find('.option').slideToggle('fast');
	});
	$('.switcher').bind('mouseleave', function() {
		$(this).find('.option').slideUp('fast');
	}); 
}); // line not present in 'header.tpl'

$(function() { // line not present in header.tpl
	$('#search input').keydown(function(e) {
		if (e.keyCode == 13) {
			moduleSearch();
		}
	});
}); // line not present in 'header.tpl'

function moduleSearch() {	
	pathArray = location.pathname.split( '/' );
	url = 'http://www.minirc.com/';
	url += 'index.php?route=product/search';
	var filter_keyword = $('#filter_keyword').attr('value')
	if (filter_keyword) {
		url += '&keyword=' + encodeURIComponent(filter_keyword);
	}
	var filter_category_id = $('#filter_category_id').attr('value');
	if (filter_category_id) {
		url += '&category_id=' + filter_category_id;
	}
	location = url;
}

// end of 'header.tpl' section

// pop up chat window
function popUp(windowLocation, windowWidth, windowHeight) {
	var id = new Date().getTime();
	var settings = "width = " + windowWidth + ", height = " + windowHeight + ", top = 0, left = 0, scrollbars = 0, location = 0, directories = 0, status = 0, menubar = 0, toolbar = 0, resizable = 0";
	var win = window.open(windowLocation,id,settings);
	win.focus();
}


