// JavaScript Document
$(document).ready(function() {
	$("#hot-product .scrollable").scrollable({circular: true})
	$('#hot-product .scrollable .items .item .con .control-mask').bind('mouseover', showText);
	$('#hot-product .scrollable .items .item .con .control-mask').bind('mouseout', hideText);
	$('#hot-product .scrollable .items .item .con .control-mask').bind('click', hrefLink);
	runBannerFirst();
	fixpng();
});

function fixpng() {
	if (ie < 9 && typeof(ie) != 'undefined') {	
		var pwidth;
		var pheight;
		var plink;
		var con;
		$('.fixpng').each(function() {
			pwidth = $(this).attr('width');
			pheight = $(this).attr('height');
			plink = $(this).attr('src');
			con = $('<div style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+plink+'\');"></div>').css({width:pwidth,height:pheight});
			$(this).parent().html(con);
		});
	}
}

function runBannerFirst() {
	var duration = 3000+$('#banner .banner:first').attr('duration')*1000;
	$('#banner .banner:first').fadeIn(1000, function() {
		$('#banner .right_text:first').show("drop", { direction: "right" } ,1000);
		$('#banner .bottom_text:first').show("drop", { direction: "down" } ,1000, function() {
			setTimeout(runBanner, duration, 0);
		});
	});
}

function showText() {
	var obj_photo = $(this).next();
	var obj_text = $(this).next().next();
	
	obj_photo.css({opacity:0.3,filter:'alpha(opacity = 30)'}, 500);
	obj_text.show();
}

function hideText() {
	var obj_photo = $(this).next();
	var obj_text = $(this).next().next();
	
	obj_photo.css({opacity:1,filter:'alpha(opacity = 100)'}, 500);
	obj_text.hide();
}

function hrefLink() {
	var nlink = $(this).attr('nlink');
	window.location.href = nlink;
}

function runBanner(num) {
	$('#banner .right_text:eq('+num+')').hide("drop", { direction: "right" } ,1000);
	$('#banner .bottom_text:eq('+num+')').hide("drop", { direction: "down" } ,1000, function() {
		$('#banner .banner:eq('+num+')').fadeOut(1000);
		if (num > $('#banner .banner').length-2) {
			num = 0;
		}
		else {
			num++;
		}
		
		var duration = 3000+$('#banner .banner:eq('+num+')').attr('duration')*1000;
		
		$('#banner .banner:eq('+num+')').fadeIn(1000, function() {
			$('#banner .right_text:eq('+num+')').show("drop", { direction: "right" } ,1000);
			$('#banner .bottom_text:eq('+num+')').show("drop", { direction: "down" } ,1000, function() {
				setTimeout(runBanner, duration, num);
			});
		});
	});
}
