function QueryString(name) 
{
	var AllVars = window.location.search.substring(1);
	var Vars = AllVars.split("&");
	for (i = 0; i < Vars.length; i++)
	{
		var Var = Vars[i].split("=");
		if (Var[0] == name) return Var[1];
	}
	return "";
}
function getAddress()
{
	var tempLink="http://maps.google.com.tw/maps?f=q&q="+QueryString("address")+"&ie=UTF8&z=14&iwloc=A&output=embed";
	//alert(tempLink);
	return tempLink;
}
//
$(document).ready(function () {	
	
	$('#nav li').hover(
		function () {
			//show its submenu
			$('ul', this).slideDown(300);

		}, 
		function () {
			//hide its submenu
			$('ul', this).slideUp(300);			
		}
	);
	
});

//

$(document).ready(function () {
	$("#albumContainer").pwi({
		username: 'sothatsmealbum',
		albums:photoAlbum,
		albumThumbSize: 162,
		thumbSize: 110,
		thumbCrop: 1,
		thumbCss: {'margin' : '6px'},
		labels: {photo:"照片", //-- override labels, to translate into your required language
                                photos: "照片",
                                albums: "回到相簿頁",
                                slideshow: "照片輪播",
                                loading: "讀取資料中...",
                                page: "頁",
                                prev: "上一張",
                                next: "下一張",
                                devider: "|"
                }
	});
	//
	//
	//
	$("#albumContainerPress").pwi({
		username: 'sothatsmealbum',
		albums:pressAlbum,
		albumThumbSize: 162,
		thumbSize: 100,
		thumbCrop: 1,
		thumbCss: {'margin' : '6px'},
		labels: {photo:"照片", //-- override labels, to translate into your required language
								photos: "照片",
                                albums: "回到相簿頁",
                                slideshow: "照片輪播",
                                loading: "讀取資料中...",
                                page: "頁",
                                prev: "上一張",
                                next: "下一張",
                                devider: "|"
                }
	});
	
	
	//
	//
	
	//video thumbnail getter
	$('a.videoBox').each(function(i) {
      //$(this).append($('<img src="'+$.jYoutube($(this).attr("id"))+'" width="165" height="125" /><span class="titleName">')).append($(this).attr("title")).append('</span>');
	  $(this).append($('<img src="'+$.jYoutube($(this).attr("id"))+'" width="165" height="125" />')).append($(this).attr("title"));
	  //alert($.jYoutube($(this).attr("id")));
	});
	
	
	//video player setter
	//$('#videoHere').append('[youtube=http://www.youtube.com/watch?v='+QueryString("vid")+']');
});
//
//

//
//
(function($){
	$.extend({
		jYoutube: function( url, size ){
			if(url === null){ return ""; }

			size = (size === null) ? "big" : size;
			var vid;
			var results;

			results = url.match("[\\?&]v=([^&#]*)");

			vid = ( results === null ) ? url : results[1];

			if(size == "small"){
				return "http://img.youtube.com/vi/"+vid+"/2.jpg";
			}else {
				return "http://img.youtube.com/vi/"+vid+"/0.jpg";
			}
		}
	})
})(jQuery);
//
//
//
//
//
//collection item
$(function(){
	$("#collectionItemsDiv div").css({'display':'none'});
	$("#tab1").css({'display':'block'});
	$("#collectionItemsDiv").siblings(".tabBtn").addClass('onTabOff');
	$("#tab1-button").removeClass('onTabOff');
	$("#tab1-button").addClass('onTabSelect');
	$("#subMenuDiv a.tabBtn").click(function(){
		$clicked = $(this);
		$clicked.addClass('onTabSelect');
		$clicked.removeClass('onTabOff');
		// if the button is not already "transformed" AND is not animated
			var idToLoad = $clicked.attr("id").split('-');
			$("#collectionItemsDiv").find("div:visible").fadeOut("fast", function(){
				$(this).parent().find("#"+idToLoad[0]).fadeIn();
			})
		$clicked.siblings(".tabBtn").removeClass('onTabSelect');
		$clicked.siblings(".tabBtn").addClass('onTabOff');
	});
	//
});

//
//
//
//hor scroll
$(function(){
	//Get our elements for faster access and set overlay width
	var div = $('div.sc_menu'),
		ul = $('ul.sc_menu'),
		ulPadding = 15;
	
	//Get menu width
	var divWidth = div.width();

	//Remove scrollbars	
	div.css({overflow: 'hidden'});
	
	//Find last image container
	var lastLi = ul.find('li:last-child');
	
	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
