﻿/*<![CDATA[*/
 


var flogControl;
document.observe('dom:loaded', function(){
	flogControl = new flog.layout();	// flog initialize
});

var flog = {};

flog.layout = Class.create({
	initialize: function(){
		this.photo = $$('img.photo_bigimg_open');
		this.setHeight();
		this.initEvent();
		if($('regMP1_open'))
			new flog.attach();
		new flog.comment();
	},
	initEvent: function(){
		this.photo.each(function(e){
			e.observe('click', this.getOrignalImage.bind(this));
		}.bind(this));
	},
	setHeight: function(){
		this.container = $('container') || false;
		this.wrapL = $('left_wrap') || false;
		this.wrapR = $('right_wrap') || false;
		this.FashionQView = $('FashionQView') || false;
		
		if (!this.container || !this.wrapL || !this.wrapR)
			return;
		this.wrapL.setStyle({height:parseInt(this.container.getHeight()) + 'px'});
		this.wrapR.setStyle({height:parseInt(this.container.getHeight()) + 'px'});
		
		if (!this.container || !this.FashionQView )
			return;
		this.FashionQView.setStyle({height:parseInt(this.container.getHeight()) + 'px'});
		
	},
	getOrignalImage: function(e){

		var element = e.element();
		//var newSrc = element.getAttribute('src').replace('thumb', 'original'); 
		//this.newImage = new Element('IMG').writeAttribute('src', newSrc); 	
		
		/* 추가_플로그 시작 */
		 
		var newSrc = element.getAttribute('src').toLowerCase();
		if ( (newSrc.indexOf("img.halfclub.com") > 0 ) || (newSrc.indexOf("gundam.stylet.com") > 0 ))
		{   
            newSrc = newSrc.substring(0, newSrc.lastIndexOf("_")) + "." + newSrc.substring(newSrc.lastIndexOf(".")+1 , newSrc.length); 
        } 
        else 
            alert(newSrc);
         
//        this.newImage = new Element('IMG').writeAttribute('src', newSrc); 	  
		  
		 this.newImage = new Element('IMG').writeAttribute('src', "http://farm3.static.flickr.com/2530/3730487665_ec48dd02ea.jpg"); 	  
		  
		/* 추가_플로그 끝 */

	
		this.newImage.observe('load', function(){  
		
			this.win = window.open("","image_window","width="+this.width+",height="+this.height+",noresize,scrollbars=no"); 
			
			this.win.document.open();  
			this.win.document.write ('<html><head><meta http-equiv="imagetoolbar" content="no" /><meta http-equiv="content-type" content="text/html; charset=euc-kr">'); 
			this.win.document.write ('<title>사진원본보기</title>'); 
			this.win.document.write ('</head>'); 
			this.win.document.write ('<body leftmargin="2" topmargin="2" bgcolor="#232323">\n'); 
			this.win.document.write ('<div><img src="/Stylet/images/Flog/layer/title_originalimage.gif" width="496" height="33" border="0" onclick="window.close()" /></div>');
			this.win.document.write ('<div><img src="'+this.src+'" width="'+(this.width+4)+'" height="'+(this.height+37)+'" border="0" onclick="window.close()" /></div>');
			this.win.document.write ('</body></html>'); 
			this.win.document.close(); 
			this.setAttribute('src','');
		});

	}
});

flog.attach = Class.create({
	initialize: function(){
		this.buttons = [$('regMP1_open'), $('regMP2_open'), $('regMP3_open'), $('regMP4_open'), $('regMP5_open')];
		this.element = [$('regMP1'), $('regMP2'), $('regMP3'), $('regMP4'), $('regMP5')];
		this.closeButtons = $$('a.attach_close');

		this.regEvent();
	},
	regEvent: function(){
		this.buttons.each(function(e, i){
			e._index = i;
			e.observe('click', this.viewAttach.bind(this));
		}.bind(this));
		this.closeButtons.each(function(e, i){
			e.observe('click', this.closeAttach.bind(this));
		}.bind(this));
	},
	viewAttach: function(e){
	 
		var element = e.element();
		if(typeof(element._index) != 'number')
			return;
			 
		
		/*  [?뚮줈洹? ?대┃??element????hide ?쒗궎??諛⑺뼢?쇰줈 ?섏젙 */	
		/*
		if(this.element[this.now]){
			this.element[this.now].hide();
		}
		*/
	    for(var i=0; i < this.element.length; i++)
	        this.element[i].hide();		 
		 
		
		this.now = element._index;
		this.element[element._index].show();
		flogControl.setHeight();
	}, 
	
	closeAttach: function(){
		if(this.element[this.now]){
			this.element[this.now].hide();
		}
		flogControl.setHeight();
	} 
});

flog.comment = Class.create({
	initialize: function(){
		this.element = $$('div.commentReg');
		this.buttons = $$('a.comment_open');

		this.regEvent();
	},
	regEvent: function(){
		this.buttons.each(function(e, i){
			e._index = i;
			e._arrow = e.getElementsByTagName('img')[0];
			e.observe('click', this.viewComment.bind(this));
			e.observe('focus', function(){this.blur()});
		}.bind(this));
	},
	viewComment: function(e){
		e.stop();
		var element = e.element();
		var arrowPath = element._arrow.getAttribute('src');
		this.element[element._index].toggle();
		if(arrowPath.indexOf('_over.gif') != -1)
			element._arrow.setAttribute('src', arrowPath.replace('_over.gif', '.gif'));
		else
			element._arrow.setAttribute('src', arrowPath.replace('.gif', '_over.gif'));
		flogControl.setHeight();
	}
});

flog.tab = Class.create({
	initialize: function(e, t){
		this.element = $(e);
		this.buttons = $(t);

		this.regEvent();
	},
	regEvent: function(){
		this.buttons._arrow = this.buttons.getElementsByTagName('img')[0];
		this.buttons.observe('click', this.viewContent.bind(this));
		this.buttons.observe('focus', function(){this.blur()});
	},
	viewContent: function(e){
		e.stop();
		var element = e.element();
		if(!element._arrow)
			return;
		var arrowPath = element._arrow.getAttribute('src');
		this.element.toggle();
		if(arrowPath.indexOf('_over.gif') != -1)
			element._arrow.setAttribute('src', arrowPath.replace('_over.gif', '.gif'));
		else
			element._arrow.setAttribute('src', arrowPath.replace('.gif', '_over.gif'));
		flogControl.setHeight();
	}
});


flog.inlistview = Class.create({
	initialize: function(b, t){
		this.buttons = $$(b);
		this.element = $$(t);

		if(this.buttons.length != this.element.length){
			alert('버튼과 컨텐츠의 개수가 맞지 않습니다. 본문태그를 확인하세요.');
			return;
		}

		this.regEvent();
	},
	regEvent: function(){
		this.buttons.each(function(e, i){
			e.observe('click', this.viewContent.bindAsEventListener(this, i));
			e.observe('focus', function(){this.blur()});
		}.bind(this));
	},
	viewContent: function(e, n){
		if(this.element[this.now]){
			this.element[this.now].hide();
		}
		this.now = n;
		this.element[n].show();
		flogControl.setHeight();
	}
});
