


// set up horizontal scroll
var setupFeaturedBoxes = function () {
	var buttons = {
		previous: {
			enabled: 'http://www.travel4u.com.tw/project/PKG_TEST/art_layout/images/picrun_left.jpg',
			hover: 'http://www.travel4u.com.tw/project/PKG_TEST/art_layout/images/picrun_left.jpg'
		},
		next: {
			enabled: 'http://www.travel4u.com.tw/project/PKG_TEST/art_layout/images/picrun_right.jpg',
			hover: 'http://www.travel4u.com.tw/project/PKG_TEST/art_layout/images/picrun_right.jpg'
		}
	};
	var featuredContentWidth = 464;		// 3 + 184 + 3  bk118
	var featuredContentScrollPrefs = {
		speed: 800,
		axis: 'x'
	};
	var j=0;
	jQuery('.featuredBox').each( function (i) {
		var featuredBox = jQuery(this);		
		featuredBox
			.find('.scrollArrow')
				.filter('.next')
					.hover(
						function () {
							jQuery(this)
								.attr( 'src', buttons.next.hover )
								.css( 'cursor', 'pointer' )
							;
						},
						function () {
							jQuery(this)
								.attr( 'src', buttons.next.enabled )
								.css( 'cursor', 'default' )
							;
						}
					)
					.click( function() {
					    if (j<=1){
						    featuredBox.find('.featuredContent').scrollTo('+=' + featuredContentWidth + 'px',featuredContentScrollPrefs);												
						    j=j+1;																								
						    return false;						
						}												
					})
				.end()
				.filter('.prev')
					.hover(
						function () {
							jQuery(this)
								.attr( 'src', buttons.previous.hover )
								.css( 'cursor', 'pointer' )
							;
						},
						function () {
							jQuery(this)
								.attr( 'src', buttons.previous.enabled )
								.css( 'cursor', 'default' )
							;
						}
					)
					.click( function() {
					    if (j>=1){
					        featuredBox.find('.featuredContent').scrollTo('-=' + featuredContentWidth + 'px',featuredContentScrollPrefs);						
						    j=j-1;						
						    return false;
					    }						
					})
					.end()
		;
	});
	jQuery('.featuredBox .featuredContent .featuredDisplayDiv').each( function (i) {
		jQuery(this).css( 'width', ( featuredContentWidth * jQuery(this).find('ul li').size() ) + 'px' );
	});
};


var MainPageUpdater = (function() {
	var self = this;
	var updated = 0;
	var executed = 0;
	var updatedTime = 0;
	var autoUpdateInterval = 5 * 60 * 1000;
	var autoUpdateTimer = null;

	this.init = function () {
		autoUpdateTimer = window.setTimeout( "MainPageUpdater.run()", autoUpdateInterval );
	};

	this.run = function () {
		executed++;
		if ( jQuery("#section_latestnews, #section_morenews").size() > 1 ) {
			jQuery.ajax({
				url: "",
				dataType: "html",
// 				ifModified: true,
// 				cache: true,
				timeout: 1000,
				success: function(html){
					var now = new Date().getTime();
					if ( now > updatedTime + autoUpdateInterval ) {
						// Create a dummy div to hold the results
						var update = jQuery("<div/>")
							// inject the contents of the document in, removing the scripts
							// to avoid any 'Permission Denied' errors in IE
							.append(
								html
									.replace(/<script(.|\s)*?\/script>/g, "")
									.replace(/<iframe.+?\/iframe>/g, "")
							)
						;

					}
				}
			});
			autoUpdateTimer = window.setTimeout( "MainPageUpdater.run()", autoUpdateInterval );
		}
		updateLatestNewsTimestamp();
	};

	this.stop = function () {
		window.clearTimeout( autoUpdateTimer );
	};

	return {
		'init': init,
		'run': run,
		'stop': stop
	};

})();



var updateLatestNewsTimestamp = function () {
	var now = new Date().getTime();
	var SECOND = 1000;
	var MINUTE = 60 * SECOND;
	var HOUR = 60 * MINUTE;
	var DAY = 24 * HOUR;
	var latestTime = 0;

};




jQuery(document).ready(function(){



// set up horizontal scroll
	setupFeaturedBoxes();


	
});
