/*
 * common.js
 */
$().ready(function(){
	PEPS.rollover.init();
	// index only
	if($("#idxNavi").size() > 0)
	{
		$("#idxNavi li a").hover(
		  function () {
				var index = $("#idxNavi li a").index($(this));
				if (!$.browser.msie || $.browser.version >= 7)
				{
					$(this).next().animate(
						{top:'95px'},
						{duration: 280, easing: "linear",
						complete: function(){}
					});
					$(this).next().next().fadeOut("slow");
					$(this).next().next().next().fadeIn("slow");
				}
				$(this).children(".btnOver").show();
				$(this).children(".btnDef").hide();
		  },
		  function () {
				var index = $("#idxNavi li a").index($(this));
				if (!$.browser.msie || $.browser.version >= 7)
				{
					$(this).next().animate(
						{top:'108px'},
						{duration: "slow", easing: "linear",
						complete: function(){ }
					});
					$(this).next().next().next().fadeOut(450);
					$(this).next().next().fadeIn(450);
				}
				$(this).children(".btnOver").hide();
				$(this).children(".btnDef").show();
		  }
		);
	}
	// Product Color Variation
	if($("#productColorPic").size() > 0)
	{
		var oldimg =  $("#productColorPic").attr('src');
		$("#productColorList li img").hover(
			function () {
				var newimg = $(this).attr('src').replace(/Thumb/, 'Pic');
				newimg = newimg.replace(/gif/, 'jpg');
				$("#productColorPic").attr('src', newimg);
			},
			function () {
				$("#productColorPic").attr('src', oldimg);
			}
		);
	}
	// window open
	if($("#functionLink").size() > 0) openWindow("#functionLink", "functionLink", "width=920,height=600,left=no,top=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
	if($("#talkLink").size() > 0) openWindow("#talkLink", "talkLink", "width=990,height=735,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
	if($("#attentionLink").size() > 0) openWindow("#attentionLink", "attentionLink", "width=920,height=480,left=no,top=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
	if($("#ipodLink").size() > 0) openWindow("#ipodLink", "ipodLink", "width=920,height=600,left=no,top=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
	if($("#ipodLink2").size() > 0) openWindow("#ipodLink2", "ipodLink", "width=920,height=600,left=no,top=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes");
});
function openWindow(linkid, wname, opt)
{
	$(linkid).click(
		function(){
			win = window.open($(linkid).attr("rel"),wname,opt);
			win.focus();
		}
	);
	$(linkid).attr("target","_self");
	$(linkid).attr("href","javascript:void(0)");

}
function changeShade(obj)
{
	obj.attr("src", obj.attr("src").replace(/_over\.png/, '.png'));
}
/*
 * Roll over
 */
PEPS = {};
PEPS.rollover = {
init: function(){
	this.preload();

	$(".over").hover(
	function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
	function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
	);},

	preload: function(){
	$(window).bind('load', function() {
	$('.over').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
	});},

	newimage: function( src ){
	return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_over' + src.match(/(\.[a-z]+)$/)[0];
	},

	oldimage: function( src ){
	return src.replace(/_over\./, '.');
	}
};

