$(function() {
	if($("#reccomendArea li").size() > 4) {
		slide("#bnrWrap", "#bnrArea", 229);
	}
	$("#reccomendArea li").hover(
		function () {
			$(this).css('opacity', 0.7)
		},
		function () {
			$(this).css('opacity', 1)
		}
	);

	var prop = $.browser.msie && $.browser.version < 7 ? "height" : "min-height";
	var h = 0;
	$('#reccomendContents > div').each(function(){
		h = Math.max(h, $(this).height());
	})
	$('#reccomendContents > div').css(prop, h);
});

function slide(wc, c, w) {
	var n = 0;

	var b = $(c + " li");
	var s = b.size();
	var aw = s * w;
	$(c).width(aw * 2);

	var cd = $("<ul></ul>").css({float:"none", width:"auto", margin: 0});
	$(b).appendTo(cd);
	cd.appendTo(c);
	$(cd).clone(true).insertAfter(cd);

	pv = $('<p class="prev"></p>');
	nt = $('<p class="next"></p>');
	pv.insertAfter(wc);
	nt.insertAfter(wc);

	var intID;
	function play(){
		intID = setInterval(function () {
			slideNext();
		}, 5000);
	}
	function slideNext(){
		n ++;
		if(n > s) {
			n -= s;
			$(c).css("left", -((n - 1) * w))
		}
		$(c).animate({left: -(n * w)}, 600, 'swing')
	}
	function slidePrev(){
		n --;
		if(n < 0) {
			n += s;
			$(c).css("left", -((n + 1) * w))
		}
		$(c).animate({left: -(n * w)}, 600, 'swing')
	}

	$(wc).hover(
		function () {
			clearInterval(intID);
		},
		function () {
			play();
		}
	);

	$(pv).hover(
		function () {
			$(this).css('opacity', 0.7)
		},
		function () {
			$(this).css('opacity', 1)
		}
	).click(function(){
		if(!$(c).is(':animated')) {
			clearInterval(intID);
			slidePrev();
			play();
		}
	}).css("cursor", "pointer");

	$(nt).hover(
		function () {
			$(this).css('opacity', 0.7)
		},
		function () {
			$(this).css('opacity', 1)
		}
	).click(function(){
		if(!$(c).is(':animated')) {
			clearInterval(intID);
			slideNext();
			play();
		}
	}).css("cursor", "pointer");

	play();
}


var flashvars = {
	url0:"/story",
	url1:"/perfectguide/",
	url2:"/tvcm/",
	url3:"/deuxa/",
	window0:"_blank",
	window1:"_self",
	window2:"_blank",
	window3:"_blank"
};
var params = {
wmode:"transparent"
};
var attributes = {};
swfobject.embedSWF("images/topflash.swf", "flashArea", "100%", "600", "9.0.0","", flashvars, params, attributes);


// pngfix
if($.browser.msie && $.browser.version < 7) DD_belatedPNG.fix('#contentsTop');


