var initSite={
	initHS:function(){
		// Apply the Highslide settings
		hs.graphicsDir = 'jscript/highslide/graphics/';
		hs.outlineType = 'rounded-white';
		hs.allowSizeReduction = true;
		hs.wrapperClassName = 'draggable-header';
		hs.align='center';
		hs.showCredits = false;
		
		$('a.POPBOX').click(function(){
			return hs.expand(this);
		});
		$('a.POPBOX-google-map').click(function(){
			var el=$(this);
			var href=el.attr('href');
			var pos=href.replace('#gmap-','');
/*			var _src='http://www.ps.co.th/dialog-google-maps.rhtml?latlng='+pos;
			return hs.htmlExpand($(this)[0], {
				objectType : 'iframe',
				src : _src,
				width : 600,
				objectHeight : 400,
				hieght : 400
			});*/
		});
	},
	initProjectContainer:function(){
		$.each($('div#containnerProject > div.PicProject'), function(i,o){
			var projectEl=$(o);
			var contentEl=projectEl.next('div.PopupContent');
			projectEl
				.mouseover(function(){
					contentEl.slideDown();
				}).mouseout(function(){
					contentEl.slideUp();
				});;
		});
	},
	initImageFlow:function(){
		var initImageFlow = function(id){
			var imageflow = new ImageFlow();
			var imgs=$("#"+id+" img");
			var count=imgs.length;
			var start=Math.round(count/2);
			imgs.each(function(i){
				var url=$(this).attr("longdesc").toLowerCase();
				if(window.location.href.toLowerCase().indexOf(url)!=-1)
					start=i+1;
			});
			imageflow.init({ ImageFlowID:id, reflections:false, reflectionP:0.4, slider:false, captions:false 		,startID:start,buttons:true,xStep: 100,imageFocusM: 1.3,imagesHeight:0.5,onClick:function(){
																																																							var _this=this;
				if(this.url){
					var visibleFlow=$('.flow-detail:visible');
					var showSelected=function(){ $('#'+_this.id+'-detail').slideDown() };
					if(visibleFlow.length>0){
						$('.flow-detail:visible').slideUp(300, function(){
							showSelected();
						});
					}else{
						showSelected();
					}
				}
			}});
			setTimeout(function(){
				$('#'+id).height(315).hide();
			}, 500);
		};
		initImageFlow("imageflow-1");
		initImageFlow("imageflow-2");
		initImageFlow("imageflow-3");
		var clearImg = function(imgs){
			imgs.each(function(){
				var img = $(this);
				if(img.is(".selected")){
					var temp = img.attr("src");
					img.attr("src",img.attr("alt"));
					img.attr("alt",temp);
					img.removeClass("selected");
				}
			});
		};
		var setImg = function(img){
			var temp = img.attr("src");
			img.attr("src",img.attr("alt"));
			img.attr("alt",temp);
			img.addClass("selected");
		};
		$("#tab-1,#tab-2,#tab-3").css("cursor","pointer");
		$("#tab-1").click(function(){
			$("#imageflow-2,#imageflow-3").hide();
			$("#imageflow-1").show();
			clearImg($("#tab-2,#tab-3"));
			setImg($("#tab-1"));			
		});
		$("#tab-2").click(function(){
			$("#imageflow-1,#imageflow-3").hide();
			$("#imageflow-2").show();
			clearImg($("#tab-1,#tab-3"));
			setImg($("#tab-2"));				
		});
		$("#tab-3").click(function(){
			$("#imageflow-1,#imageflow-2").hide();
			$("#imageflow-3").show();
			clearImg($("#tab-1,#tab-2"));
			setImg($("#tab-3"));				
		});
		setTimeout(function(){$("#tab-1").click();},500);
	}
};

$(function(){
	initSite.initHS();
	//initSite.initProjectContainer();
	//initSite.initImageFlow();
});
