/**
 * Shopping Cast
 */

// ÇÃ·¡½¬ °ü·Ã ÇÔ¼ö begin

var delimeter4FlashUse="|";//ÇÃ·¡½Ã¿¡¼­ »ç¿ëÇÒ ½ºÆ®¸µ µ¨¸®¹ÌÅÍ ¼±¾ð

// ÇØ´ç ÇÃ·¡½¬¸¦ ¸®ÅÏ 
function getFlash(flashName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[flashName];
	}
	else {
		return document[flashName];
	}
}

//  ÇÃ·¡½¬·Î »óÇ°Á¤º¸ Àü¼Û  
function sendProdInfoToFlash(info) {

	var prodInfo = new Array();
	prodInfo.push(info.image);
	prodInfo.push(info.category);
	prodInfo.push(info.prdname);
	prodInfo.push(info.customerprice);
	prodInfo.push(info.salesprice);
	prodInfo.push("/shop/product/?id=" +info.prodno);
	
	try {
		getFlash("ProductBriefInfo").sendProdInfoToFlash(prodInfo.join(delimeter4FlashUse));
	}
	catch( e ) {
		setTimeout(function() {
			sendProdInfoToFlash(info)
		}, 100);
		return;
	}
}

// ÇÃ·¡½¬·Î °¡°ÝÁ¤º¸ Àü¼Û
function sendPriceInfoToFlash(info) {
	var price = null;
	if( !info.salescouponprice || info.salescouponprice == "0" ) {
		price = info.salesprice
	}
	else {
		price = info.salescouponprice
	}
	
	try {
		getFlash("ProductPrice").sendPriceInfoToFlash(price + "¿ø");
	}
	catch( e ) {
		setTimeout(function() {
			sendPriceInfoToFlash(info)
		}, 100);
		return;
	}
}

// ÇÃ·¡½¬·ÎºÎÅÍ ¿µ»ó ÇÃ·¹ÀÌ°¡ ³¡³µÀ½À» ¼ö½Å 
function playCompletedFromFlash() {
	jvShoppingCast.next(true);
}

// ÇÃ·¡½¬°¡ ½ÇÇàÇÒ À§Á¬Á¤º¸ Àü¼Û (ÃßÈÄ ±¸Çö)
function sendWidgetInfoToFlash(widgetseq) {
	getFlash("widgetFlash").sendWidgetInfoToFlash(widgetseq);
}

// ÇÃ·¡½¬ °ü·Ã ÇÔ¼ö end


var jvShoppingCast = {

	widgetseq: null,		// ÇöÀç ¹æ¼ÛÁßÀÎ À§Á¬¹øÈ£
	list: new Array(),		// ¹æ¼ÛÆí¼ºÇ¥ info ±¸¼º("widgetseq","prodno","prdname","time")
	listCnt: 0,				// ¹æ¼ÛÆí¼ºÇ¥ °¹¼ö
	playerDiv: null,		// 
	currIdx: 0,				// ÇöÀç ¹æ¼ÛÁßÀÎ ¹æ¼ÛÀÇ ÀÎµ¦½º
	broadListDiv: null,		// ¹æ¼ÛÆí¼º¸ñ·Ï
	playPrevImg: null,		// ÀÌÀü¿µ»ó
	playNextImg: null,		// ´ÙÀ½¿µ»ó
	broadListImg: null,		// ¼îÇÎ¹æ¼ÛÆí¼ºÇ¥ ÀÌ¹ÌÁö

	// <%-- ÃÊ±âÀÛ¾÷ --%>
	initialize: function() {
		this.broadListDiv	= jQuery('#broad_list_div');
		//this.setData();
		this.playerDiv		= document.getElementById("player_div");
		this.playPrevImg	= document.getElementById("play_prev_img");
		this.playNextImg	= document.getElementById("play_next_img");
		this.broadListImg	= document.getElementById("broad_list_img");

		if( this.listCnt > 0 ) {
			this.setProdData(0);	// ¸ñ·ÏÀÇ Ã¹¹øÂ°¿¡ ÀÖ´Â »óÇ°Á¤º¸¸¦ ¼¼ÆÃ
		}
		

		// <%-- on,off ÀÌ¹ÌÁö --%>
		jQuery('.onoff_img_class').each(function() {
			this.onmouseover = function() {
				this.src = this.src.replace("_off", "_on");
			};
			this.onmouseout = function() {
				this.src = this.src.replace("_on", "_off");
			};
		});

		// <%-- µµ¿ò¸» --%>
		jQuery('#question_img')
			.bind('mouseover', function() {
				jQuery('#MoneyHelp').show();
			})
			.bind('mouseout', function() {
				jQuery('#MoneyHelp').hide();
			}
		);

		// <%-- Â¯¸Ó´Ï¹ú±â µµ¿ò¸» --%>
		jQuery('#jjangmoney_help_img')
			.bind('mouseover', function() {
				jQuery('#jjangMoneyHelp').show();
			})
			.bind('mouseout', function() {
				jQuery('#jjangMoneyHelp').hide();
			}
		);

			
	},

	// <%-- ¹æ¼ÛÆí¼ºÇ¥ º¸±â --%>
	showBroadList: function() {
		this.broadListDiv.show();
		this.broadListImg.onmouseover = function() {
		};
		this.broadListImg.onmouseout = function() {
		};
		this.broadListImg.src = "/images/shopping/main_new/btn_shopping_time_line_on.gif";
	},

	// <%-- ¹æ¼ÛÆí¼ºÇ¥ °¨Ãß±â --%>
	hideBroadList: function() {
		this.broadListDiv.hide();
		this.broadListImg.onmouseover = function() {
			this.src = this.src.replace("_off", "_on");
		};
		this.broadListImg.onmouseout = function() {
			this.src = this.src.replace("_on", "_off");
		};
		this.broadListImg.src = "/images/shopping/main_new/btn_shopping_time_line_off.gif";
	},

	// <%-- ÃÊ±â µ¥ÀÌÅ¸ ¼¼ÆÃ --%>
	setData: function() {
	},

	// <%-- »óÇ°Á¤º¸ ¼¼ÆÃ, currIdx °¡ ÀÖ´Â °æ¿ì´Â ¸ñ·Ï¿¡¼­ Å¬¸¯ÇÑ °æ¿ì --%>
	setProdData: function(idx, currIdx) {
		var info = this.list[idx];

		if( !info ) {
			return;
		}

		if( currIdx == 0 || currIdx ) {
			this.currIdx = currIdx;
			this.hideBroadList();
		}

		var self = this;
		jQuery.post(
			'/shopping/main/getProductJSON.jsp',
			{
				prodno: info.prodno,
				ts: new Date().getTime()
			},
			function(json, textStatus) {
				if( json.result == 'ok' ) {
					json.prdname = info.prdname;	// »óÇ°¸íÀº °ü¸®ÀÚ ÆäÀÌÁö¿¡¼­ ¼öÁ¤µÈ ÀÌ¸§À» »ç¿ë
					
					sendProdInfoToFlash(json);		// »óÇ°Á¤º¸
					sendPriceInfoToFlash(json);		// ÇÒÀÎÇìÅÃÀû¿ë°¡
					self.viewWidget(idx);			// µ¿¿µ»ó ÇÃ·¹ÀÌ
					self.setPlayImg();				// ÀÌÀü¿µ»ó, ´ÙÀ½¿µ»ó ¹öÆ° ¼¼ÆÃ
				}
				else {
					alert(json.msg);
				}
			},
			'json'
		);
	},

	// <%-- ÇÃ·¹ÀÌ¾î ¹öÆ° ¼¼ÆÃ --%>
	setPlayImg: function() {

		var self = this;

		this.playPrevImg.style.cursor	= "pointer";
		this.playPrevImg.src			= "/images/shopping/main_new/btn_prev_movie_on.gif";
		this.playPrevImg.onclick = function() {
			self.prev();
		};

		this.playNextImg.style.cursor	= "pointer";
		this.playNextImg.src			= "/images/shopping/main_new/btn_next_movie_on.gif";
		this.playNextImg.onclick = function() {
			self.next();
		};

		if( this.currIdx == 0 ) {
			this.playPrevImg.style.cursor	= "";
			this.playPrevImg.src			= "/images/shopping/main_new/btn_prev_movie_off.gif";
			this.playPrevImg.onclick = function() {
			};
		}

		if( this.currIdx  == (this.listCnt-1) ) {
			this.playNextImg.style.cursor	= "";
			this.playNextImg.src			= "/images/shopping/main_new/btn_next_movie_off.gif";
			this.playNextImg.onclick = function() {
			};
		}
	},

	// <%-- À§Á¬ º¸±â --%>
	viewWidget: function(idx) {
		var info = this.list[idx];
		if (info) {
			jQuery("#player_div").load("/shop/main/shoppingCastPlayer.jsp", { widgetseq: info.widgetseq });
		}
	},

	// <%-- ÀÌÀü À§Á¬ ÇÃ·¹ÀÌ --%>
	prev: function() {
		if( this.currIdx == 0 ) {
			return;
		}
		this.currIdx--;
		this.setProdData(this.currIdx);
	},

	// <%-- ´ÙÀ½ À§Á¬ ÇÃ·¹ÀÌ --%>
	next: function(repeat) {
		if( this.currIdx == (this.listCnt - 1) ) {
			if( repeat ) {	// ÇÃ·¹ÀÌ¾î¿¡¼­ ¿Ã °æ¿ì´Â ¹Ýº¹
				this.currIdx = 0;
			}
			else {
				return;
			}
		}
		else {
			this.currIdx++;
		}
		this.setProdData(this.currIdx);
	},

	// <%-- ÆÛ°¡±â --%>
	copyWidget: function() {
		var info = this.list[this.currIdx];
		var url = "http://www.jjanglive.com/hompy.main.jjang?cmd=jjangMoneyPopup&prodno="+info.prodno;
		this.openGeneralWindow(url, "copywidget", 370, 329);
	},

	// <%-- ¸ÞÀÏº¸³»±â --%>
	mail: function() {			// ¸ÞÀÏº¸³»±â
		var info = this.list[this.currIdx];
		var prodnoArry = "";
		for(i=0;i<this.list.length;i++){
			var infoarry=this.list[i];
			prodnoArry+=infoarry.prodno+",";
		}
		if( info ) {
			window.open("/shopping/main/shopMail.jsp?widgetseq="+info.widgetseq+"&id="+prodnoArry, "", "width=460,height=400" );
		}
	},
	
	openGeneralWindow: function (URL,title,w_width,h_height) {
		var str;
		var scrWidth = (screen.availWidth / 2 ) - w_width/2;
		var scrHeight = (screen.availHeight / 2) - h_height/2;
		str="'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,";
		str=str+"width="+w_width;
		str=str+",height=" + h_height + "',top="+scrHeight+",left="+scrWidth;
		wopen = window.open(URL,title,str);
	},
	
	doNothing: function() {}
}

