/**
 * common JavaScript
*/

/******************************
* flash - get url function
******************************/
function getLocation(){
	return window.location.href;
}

/******************************
* Qoo common functions
******************************/

var Qoo = new Object();

Qoo.addEventListener = function(elm,type,func,useCapture){
	if(!elm){return false;}
	if(!useCapture){
		useCapture = false;
	}
	if(elm.addEventListener){
		elm.addEventListener(type,func,false);
	}else if(elm.attachEvent){
		elm.attachEvent('on'+type,func);
	}else{
		return false;
	}
	return true;
};

Qoo.preventDefault = function(evt){
	if(evt && evt.preventDefault){
		evt.preventDefault();
		evt.currentTarget['on'+evt.type] = function(){return false;};
	}else if(window.event){
		window.event.returnValue = false;
	}
}


Qoo.$ = function(elm){
	if(document.getElementById(elm)){
		return document.getElementById(elm);
	}else{
		return false;
	}
}

Qoo.rollOverInit = function(img){
	var on = new Image();
	var off = new Image();
	off.src = img.src;
	
	var dot = img.src.lastIndexOf(".");
	on.src = img.src.substr(0,dot) + "_on" + img.src.substr(dot,img.src.length);
	
	Qoo.addEventListener(img,"mouseover",function(){if(img.src.indexOf("_on.")==-1){img.src = on.src;}});
	Qoo.addEventListener(img,"mouseout",function(){img.src = off.src});
}

Qoo.rollOverInitInId = function(id,filter){
	var elm = Qoo.$(id);
	var imgs = elm.getElementsByTagName("IMG");
	for(var i=0;i<imgs.length;i++){
		if(filter!=false){
			Qoo.rollOverInit(imgs.item(i));
		}
	}
}

/******************************
*  Open Window
******************************/

function openWin(url,winname){
	param = "width=920,height=715,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
	newwin = window.open("",winname,param);
	newwin.location.href = url;
	newwin.focus();
}
function openWin_pop(url,winname){
	param = "width=538,height=765,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
	newwin = window.open("",winname,param);
	newwin.location.href = url;
	newwin.focus();
}
function openWinStory(evt){
	Qoo.preventDefault(evt);
	param = "width=918,height=652,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
	newwin = window.open("/story/","storyWin",param);
}

/******************************
*  index.html init
******************************/

Qoo.topInit = function(){
	var flashvars = {
		NV_PATH: "common/swf/navigation.swf",
		RB_PATH: "swf/rotationBanner.swf",
		RB_DATA: "/xml/rotationBanner.xml",
		RB_INTERVAL: 5
	};
	
	var params = {
		play: "true",
		loop: "false",
		menu: "false",
		quality: "best",
		wmode: "opaque",
		bgcolor:"#FFFFFF"
	};
	
	var attributes = {id: "contents"};
	
	var d = new Date();
	
	
	swfobject.embedSWF("swf/top.swf?" + d.getTime(), "navigation", "100%", "445", "8.0.0", null, flashvars, params, attributes);
}

/******************************
*  contents page init
******************************/

Qoo.contentsInit = function(){
	var flashvars = {};
	
	var params = {
		play: "true",
		loop: "false",
		menu: "false",
		quality: "best",
		wmode: "transparent",
		bgcolor:"none"
	};
	
	var attributes = {id: "contents"};
	
	swfobject.embedSWF("/common/swf/navigation.swf", "navigation", "919", "105", "8.0.0", null, flashvars, params, attributes);
}


Qoo.loadMainWindow = function(url){
	//var url = window.opener.location.href;
	window.opener.location.href = url;
}

/******************************
*  all page onload function
******************************/

function init(){
		
	if(Qoo.$("side_navigation") && Qoo.$("side_navigation").getElementsByTagName("ul").length>0){
		var imgs = Qoo.$("side_navigation").getElementsByTagName("ul").item(0).getElementsByTagName("IMG");
		for(var i=0;i<imgs.length;i++){
			Qoo.rollOverInit(imgs.item(i));
		}
	}
	
	if(Qoo.$("page_banner")){
		Qoo.rollOverInitInId("page_banner",true);
	}
	
	if(Qoo.$("to_pgtop")){
		Qoo.rollOverInitInId("to_pgtop",true);
	}

	if(Qoo.$("index")){
		var imgs = Qoo.$("top_pickup").getElementsByTagName("ul").item(0).getElementsByTagName("IMG");
		for(var i=0;i<imgs.length;i++){
			Qoo.rollOverInit(imgs.item(i));
		}
		
		var ancs = Qoo.$("container").getElementsByTagName("a");
		for(var i=0;i<ancs.length;i++){
			if(ancs.item(i).href.indexOf("/story/")>1){
				Qoo.addEventListener(ancs.item(i),"click",openWinStory);
			}
		}
		
	}else if(Qoo.$("side_banners")){
		var ancs = Qoo.$("side_banners").getElementsByTagName("a");
		for(var i=0;i<ancs.length;i++){
			if(ancs.item(i).href.indexOf("/story/")>1){
				Qoo.addEventListener(ancs.item(i),"click",openWinStory);
			}
		}
	}
}

Qoo.addEventListener(window,'load',init);