/*
	Cross-Browser Split 0.3
	By Steven Levithan <http://stevenlevithan.com>
	MIT license
	Provides a consistent cross-browser, ECMA-262 v3 compliant split method
*/
String.prototype._$$split = String.prototype._$$split || String.prototype.split;

String.prototype.split = function (s /* separator */, limit) {
	// if separator is not a regex, use the native split method
	if (!(s instanceof RegExp))
		return String.prototype._$$split.apply(this, arguments);

	var	flags = (s.global ? "g" : "") + (s.ignoreCase ? "i" : "") + (s.multiline ? "m" : ""),
		s2 = new RegExp("^" + s.source + "$", flags),
		output = [],
		origLastIndex = s.lastIndex,
		lastLastIndex = 0,
		i = 0, match, lastLength;

	/* behavior for limit: if it's...
	- undefined: no limit
	- NaN or zero: return an empty array
	- a positive number: use limit after dropping any decimal
	- a negative number: no limit
	- other: type-convert, then use the above rules
	*/
	if (limit === undefined || +limit < 0) {
		limit = false;
	} else {
		limit = Math.floor(+limit);
		if (!limit)
			return [];
	}

	if (s.global)
		s.lastIndex = 0;
	else
		s = new RegExp(s.source, "g" + flags);

	while ((!limit || i++ <= limit) && (match = s.exec(this))) {
		var emptyMatch = !match[0].length;

		// Fix IE's infinite-loop-resistant but incorrect lastIndex
		if (emptyMatch && s.lastIndex > match.index)
			s.lastIndex--;

		if (s.lastIndex > lastLastIndex) {
			// Fix browsers whose exec methods don't consistently return undefined for non-participating capturing groups
			if (match.length > 1) {
				match[0].replace(s2, function () {
					for (var j = 1; j < arguments.length - 2; j++) {
						if (arguments[j] === undefined)
							match[j] = undefined;
					}
				});
			}

			output = output.concat(this.slice(lastLastIndex, match.index));
			if (1 < match.length && match.index < this.length)
				output = output.concat(match.slice(1));
			lastLength = match[0].length; // only needed if s.lastIndex === this.length
			lastLastIndex = s.lastIndex;
		}

		if (emptyMatch)
			s.lastIndex++; // avoid an infinite loop
	}

	// since this uses test(), output must be generated before restoring lastIndex
	output = lastLastIndex === this.length ?
		(s.test("") && !lastLength ? output : output.concat("")) :
		(limit ? output : output.concat(this.slice(lastLastIndex)));
	s.lastIndex = origLastIndex; // only needed if s.global, else we're working with a copy of the regex
	return output;
};
/* END Cross-Browser Split 0.3 */

/**
 * @author J2media
 * @copyright 2008-2009
 */
$(function(){
	if ($.browser.msie) {
		$('input:checkbox').click(function() { this.blur(); this.focus(); });
	}

    var itmphtsTh; var itmphtsTs;
	$('.pht .itms').cycle({fx: 'fade',timeout: 5000});
	//$('.pht2 .itms').cycle({fx: 'fade',timeout: 10000});
	setTimeout(function() {
		$('.pnl').slideToggle('slow');
		//$('.pnl').show("slide", { direction: "right" }, 1500);	
		//itmphtsTh = setTimeout(function() {
		//	$('.pnl').hide("slide", { direction: "right" }, 1500);	
		//},5000);
	},2500);

	$('.itmpht').bind("load", function(event){
		$(this).fadeIn('slow'); 
	});
	$('.itmpht').bind("mouseover", function(event){
	//	clearTimeout(itmphtsTh);
	//	if ($('.pnl').css('display')=='none') {
	//		$('.pnl').show("slide", { direction: "right" }, 1500);	
	//	}
	});
	$('.itmpht').bind("mouseout", function(event){
	//	if ($('.pnl').css('display')!='none') {
	//		itmphtsTh = setTimeout(function() {
	//			$('.pnl').hide("slide", { direction: "right" }, 1500);	
	//		},250);
	//	}
	});
	$('.pnl').bind("mouseover", function(event){
	//	clearTimeout(itmphtsTh);
	});
	$('.pnl').bind("mouseout", function(event){
	//	if ($('.pnl').css('display')!='none') {
	//		itmphtsTh = setTimeout(function() {
	//			$('.pnl').hide("slide", { direction: "right" }, 1500);	
	//		},250);
	//	}
	});

	$('.itmphts .tbx3').bind("click", function(event){
		event.preventDefault();
		var itemimg = $('.itmpht');
		var itemhref = $(this).attr('href');
		$(itemimg).fadeOut('slow',function() {
			$(itemimg).attr('src',itemhref);
		});
	});

	$('.pht2 .i1').each(function(){
		$(this).find('.ttl,.ttlh,.img,.btnmr').show();
		var urlString = /(.+\/)(.+_)([0-9]+)\.gif$/;
		var baseURL = $(this).find('.nr img').attr('src').split(urlString);
		var onURL = ''+baseURL[1]+baseURL[2]+baseURL[3]+'a.gif';
		$(this).find('.nr img').attr('src',onURL);
	});

	$('.pht2 .itms .nr').bind("click", function(event){
		event.preventDefault();
		var urlString = /(.+\/)(.+_)([0-9]+)\.gif$/;
		var itemsrc = $(this).find('img').attr('src');
		var baseURL = itemsrc.split(urlString);
		var onURL = ''+baseURL[1]+baseURL[2]+baseURL[3]+'a.gif';
		//var offURL = 'nr_'+baseURL[1]+'a.gif';
		$(this).find('img').attr('src',onURL);
		$(this).parent().siblings().find('.nr img').each(function() {
			var urlString = /(.+\/)(.+_)([0-9]+)\a.gif$/;
			var itemsrc = $(this).attr('src');
			var baseURL = itemsrc.split(urlString);
			if (baseURL[1]!==undefined) {
				var offURL = ''+baseURL[1]+baseURL[2]+baseURL[3]+'.gif';
				$(this).attr('src',offURL);
			}
		});
		$(this).parent().siblings().find('.ttl,.ttlh,.img,.btnmr').hide();
		$(this).parent().find('.ttl,.ttlh,.img,.btnmr').show();
	});

	$('.mnu0h a').bind("mouseover",function(){
		var urlString = /\/gfx\/mnu0_([0-9]+)\.png$/;
		var baseURL = $(this).find('img').attr('src').split(urlString);
		if (baseURL[1]!==undefined) {
			var onURL = '/gfx/mnu0_'+baseURL[1]+'a.png';
			$(this).find('img').attr('src',onURL);
		}
	});
	$('.mnu0h a').bind("mouseout",function(){
		var urlString = /\/gfx\/mnu0_([0-9]+)a\.png$/;
		var baseURL = $(this).find('img').attr('src').split(urlString);
		if (!$(this).find('img').hasClass('on')) {
			var onURL = '/gfx/mnu0_'+baseURL[1]+'.png';
			$(this).find('img').attr('src',onURL);
		}
	});

	$(document).pngFix();
});