/** 
 * FestivalTrip.js
 * 
 */

var Dom = YAHOO.util.Dom;
var Anim = YAHOO.util.Anim;
var Motion = YAHOO.util.Motion;
var Event = YAHOO.util.Event;
var DDM = YAHOO.util.DragDropMgr;

function init() {

	//** Init UI Component.
	InitUIApp.init();
	
	//** Init memu component.
	TripFuncBtnApp.init();
	
	//** Init DD Source Object.
	TripDDSourceApp.init('m_ts_brk_photo');

}

//**********************************************
// Init UI Component
//**********************************************
var poiNavPage = 1;
var poiNavPageAll = 1;
var pois;
var perPage = 4;

InitUIApp = {
	init: function() {

		pois = Dom.getElementsByClassName('relatedPOI');
		var poisCount = pois.length;	

		if ((poisCount%perPage) == 0) poiNavPageAll = poisCount/perPage;
		else poiNavPageAll = parseInt(poisCount/perPage) + 1;

		InitUIApp.movePoiPage(poiNavPage);
		
		Event.on('movePoiPrevious', 'click', function(){
			if (poiNavPage == 1) {
				alert('已到第一筆資料!');
				return false;
			}
			poiNavPage = poiNavPage - 1;
			InitUIApp.movePoiPage(poiNavPage);
		});

		Event.on('movePoiNext', 'click', function(){
			if (poiNavPage == poiNavPageAll) {
				alert('已到最後一筆資料!');
				return false;
			}
			poiNavPage = poiNavPage + 1;
			InitUIApp.movePoiPage(poiNavPage);
		});
		
		Event.on(Dom.getElementsByClassName('showTripDetail'), 'click', function(e) {
			var isLoginUser=Dom.get('FestivalTripForm').isLoginUser.value;
			var target = YAHOO.util.Event.getTarget(e);
			selectedTripId = target.id.substring(5);
			if (isLoginUser=='F')
				window.open('/wps/portal/imove/TripDetail?TRIP='+selectedTripId,'_self', '');
			else 
				window.open('/wps/myportal/imove/TripDetail?TRIP='+selectedTripId,'_self', '');
		});

	},
	
	movePoiPage: function(goPage) {
		
		for (var i = 0; i < pois.length; i++) {
			Dom.setStyle(pois[i], 'display', 'none');
		}

		var startIdx = (goPage - 1) * perPage;
		for (var i = startIdx; i < startIdx + perPage; i++) {
			if (i < pois.length) Dom.setStyle(pois[i], 'display', '');
		}

	},
	
	changePage: function(targetPage) {
		Dom.get('FestivalTripForm').currentPage.value = targetPage;
		Dom.get('FestivalTripForm').submit();
	},
	
	showPOIDetail:function (selectedPoiId) {
		var isLoginUser=Dom.get('FestivalTripForm').isLoginUser.value;
		if (isLoginUser=='F')
			window.open('/wps/portal/imove/POIDetail?POI='+selectedPoiId,'_self', '');
		else 
			window.open('/wps/myportal/imove/POIDetail?POI='+selectedPoiId,'_self', '');	
	}
	
	
};
