//제품소개 배너 아이콘 선택시 
function product_index(index){
	var bg_h = index * -81;

	for(var i=0; i<=3;i++){
		if(i==index){
			Ext.get('product_list'+i).setStyle({backgroundPosition:'0px -7px'});
			continue;
		}else{
			Ext.get('product_list'+i).setStyle({backgroundPosition:'0px 0px'});
		}
	}
	
	Ext.get('product_banner').setStyle({backgroundPosition:'0px '+bg_h+'px'});
	Ext.get('product_banner').fadeIn({duration: .8});
}

Ext.onReady(function(){
	VideoJS.setupAllWhenReady();
	if ( Ext.isIE6 || Ext.isIE7 || Ext.isIE8)	{
		Ext.get('promote_video').removeClass('video-js-box');
	}
		
	// 홍보동영상 클릭시 이벤트 처리
	var video_tpl =  Ext.DomHelper.createTemplate({tag:'video', cls:'video-js', width:425, height:239, controls:true, autoplay:true, poster:'{image}', cn:[{
		tag:'source', type:'video/mp4', src:'{mp4}'
	}, {
		tag:'source', type:'video/webm', src:'{webm}'
	}, {
		tag:'object', id:'flash_fallback_1', cls:'vjs-flash-fallback', wmode:'transparent', width:425, height:239, type:'application/x-shockwave-flash', data:'http://releases.flowplayer.org/swf/flowplayer-3.2.7.swf', cn:[{
			tag: 'param', name:'movie', value:'http://releases.flowplayer.org/swf/flowplayer-3.2.7.swf'
		}, {
			tag: 'param', name:'allowfullscreen', value:'true'
		}, {
			tag: 'param', name:'wmode', value:'transparent'
		}, {
			tag: 'param', name:'flashvars', id:'flashvars', value:'config={\'playlist\':[\'http://www.xkeeper.com/{image}\', {\'url\': \'http://www.xkeeper.com/{mp4}\',\'autoPlay\':true,\'autoBuffering\':true}]}'
		}]
	}]});
	Ext.each(Ext.query('ul#promote_list > li > a'), function(item, index)	{
		Ext.get(item).on('click', function()	{
			video_tpl.overwrite('promote_video', {
				image: 'image/index/iphone_mv'+(index+1)+'.png',
			    mp4: 'image/index/iphone_mv'+(index+1)+'.mp4',
			    webm: 'image/index/iphone_mv'+(index+1)+'.webm'
			});
			
			VideoJS.setupAllWhenReady();
		})
	});
	
	Ext.get('step1').on('click', function()	{
		Ext.get('step2').setWidth(130);
		Ext.get('step3').setWidth(130);
		Ext.get('step1').setWidth(720);
		Ext.get('promote_list').show();
	});
	Ext.get('step2').on('click', function()	{
		Ext.get('promote_list').hide();
		Ext.get('step1').setWidth(130);
		Ext.get('step3').setWidth(130);
		Ext.get('step2').setWidth(720);
	});
	Ext.get('step3').on('click', function()	{
		Ext.get('promote_list').hide();
		Ext.get('step1').setWidth(130);
		Ext.get('step2').setWidth(130);
		Ext.get('step3').setWidth(720);
	});
	
	// 공지사항
	new Ext.data.JsonStore({
		autoLoad: {params: { limit:3 , start:0, category: 'Notice' }},
		url:'/news/list.php',
		totalProperty: 'results',
		root: 'rows',
		remoteSort: true,
		sortInfo: {field:'Date_Publish', direction:'DESC'},
		fields: [{name: 'Board', type: 'int'},'Title',{name: 'Date_Publish', type: 'date', dateFormat: 'Y-m-d'},{name: 'Hits', type: 'int'}],
		listeners: {
			'load': function(ds, records, options)	{
				for(i=0; records[i]; i++)	{
					Ext.DomHelper.append('notice_list', {tag:'li', cls:'normal', children: [{
						tag: 'div', cls: 'date', html: records[i].get('Date_Publish').format('[Y.m.d]')
					}, {
						tag: 'a', href: '/news/view.php?no='+records[i].get('Board'), html: Ext.util.Format.ellipsis(records[i].get('Title'), 24)
					}]});
				}
			}
		}
	});
	
	// 관련소식
	new Ext.data.JsonStore({
		autoLoad: {params: { limit:3 , start:0, category: 'News' }},
		url:'/news/list.php',
		totalProperty: 'results',
		root: 'rows',
		remoteSort: true,
		sortInfo: {field:'Date_Publish', direction:'DESC'},
		fields: [{name: 'Board', type: 'int'},'Title',{name: 'Date_Publish', type: 'date', dateFormat: 'Y-m-d'},{name: 'Hits', type: 'int'}],
		listeners: {
			'load': function(ds, records, options)	{
				for(i=0; records[i]; i++)	{
					Ext.DomHelper.append('news_list', {tag:'li', cls:'normal', children: [{
						tag: 'div', cls: 'date', html: records[i].get('Date_Publish').format('[Y.m.d]')
					}, {
						tag: 'a', href: '/news/view.php?no='+records[i].get('Board'), html: Ext.util.Format.ellipsis(records[i].get('Title'), 24)
					}]});
				}
			}
		}
	});
	
	// 팝업레이어 관련 쿠키생성
	var cp = new Ext.state.CookieProvider({
		expires: new Date(new Date().getTime()+(1000*60*60*24)), //1 day
		domain: "www.xkeeper.com"
	});

	// 이벤트 팝업	
	if( cp.get('allow_popup', true))	{
		popup = new Ext.Window({
			id: 'popup_window',
			autoLoad: { url: '/news/event/index_popup.html' },
//			bodyStyle: 'background-color: #FFFFFF; border:2px solid #77933C; padding: 0px;',
			frame: false,
			shadow: false,
			closable: false,
			resizable: false,
			width: 500,
			cp: cp,
//			x: Ext.get('mainArea').getX()+330,
			y: Ext.get('step_content').getY()
		}).show();
		_gaq.push(['_trackPageview', '/index_popup']);
	
//		new Ext.util.DelayedTask(function()	{
//			popup.close();
//		}).delay(12000);
	}
	
	//홍보동영상 보기 클릭시 삭제하기
//	Ext.get('promote_open').on('click', function()	{
//		popup = new Ext.Window({
//			id: 'promote_window',
//			autoLoad: { url: '/promote_popup.html' },
//			bodyStyle: 'background-color: #FFFFFF; border:3px solid #BCE0DC; padding: 1px;',
//			frame: false,
//			shadow: false,
//			closable: false,
//			resizable: false,
//			modal : true,
//			width: 855,
//			y: Ext.get('mainArea').getY(),
//			listeners: {
//				'close':function(){
//					Ext.TaskMgr.start(rolling_control);
//				}
//			}
//		}).show(this,function(){
//			Ext.TaskMgr.stop(rolling_control);
//		});
//	});	
	
	//제품소개 롤링 배너
	var rolling = function(){
		var index = (((parseInt(Ext.get('product_banner').getStyle('backgroundPosition').substring(3)) / -81) +1 ) % 4 );
		var bg_h = index * -81;

		for(var i=0; i<=3;i++){
			if(i==index){
				Ext.get('product_list'+i).setStyle({backgroundPosition:'0px -7px'});
			}else{
				Ext.get('product_list'+i).setStyle({backgroundPosition:'0px 0px'});
			}
		}
		
		Ext.get('product_banner').setStyle({backgroundPosition:'0px '+bg_h+'px'});
		Ext.get('product_banner').fadeIn({duration: .8});
	};
	
	new Ext.util.DelayedTask(function()	{
		Ext.TaskMgr.start({
		    run: rolling,
		    interval: 4500
		});
	}).delay(4500);
});

