function Gmap_addressGps(search) {
 var myGeocoder = new GClientGeocoder();
 var address = search;
 myGeocoder.getLatLng(address, function getRequest( point ){
   if(!point){
      alert('這個地址 Google 說不知道！');
   }else{
	  myMap = new GMap2(document.getElementById("my_map"));  
	  var myLatLng = new GLatLng();
	  myMap.addControl(new GLargeMapControl());
	  myMap.setCenter(point, 16);  
	  var marker = new GMarker(point);   
	  myMap.addOverlay(marker);  
   }
  });
}
/* Video */
function show_video(video,width,height,auto,mute){
	var so = new SWFObject('js/player.swf', 'ply', width, height, '9', '');
	so.addParam('allowfullscreen', 'true');
	so.addParam('allowscriptaccess', 'always');
	so.addParam('wmode', 'opaque');
	so.addVariable('file', video+'.flv'); // Video File
	so.addVariable('fullscreen', 'true');
	so.addVariable('stretching', 'uniform');
	so.addVariable('repeat', 'false');
	so.addVariable('icons','false');
	so.addVariable('dock', 'false');
	so.addVariable('autostart', auto);
	so.addVariable('mute', mute);
	so.write('media_container');
}
function index_video(video,width,height,auto,mute){
	var so = new SWFObject('js/player.swf', 'ply', width, height, '9', '');
	so.addParam('allowfullscreen', 'true');
	so.addParam('allowscriptaccess', 'always');
	so.addParam('wmode', 'opaque');
	so.addVariable('file', video+'.flv'); // Video File
	so.addVariable('fullscreen', 'true');
	so.addVariable('stretching', 'uniform');
	so.addVariable('repeat', 'always');
	so.addVariable('icons','false');
	so.addVariable('dock', 'false');
	so.addVariable('autostart', auto);
	so.addVariable('mute', mute);
	so.write('video');
}

function feature_box(){
	$('.top-container .loader').remove();
	$('.top-container dl').fadeIn('middle');
	$('.top-container dl').cycle({
		fx:     'fade',
		timeout: 31000,
		slideExpr: 'dd',
		before: function(curr, next, opts){
			var index = ($(next).index()-1)/2;
			$('.top-container dl dt').removeClass('active');
			$('.top-container dl dt:eq('+index+')').addClass('active');
			/*
			if(index==3){
				index_video();
			}
			*/
		}
	});
	$('.top-container dl dt').click(function(){
		var index=$(this).index()/2;
		$('.top-container dl').cycle(index);
		if(index==3){
			index_video();
		}
		return false;
	});
}

function feature_box_v2(){
	$('.index-middle .loader').remove();
	$('.index-middle dl').fadeIn('middle');
	$('.index-middle dl').cycle({
		fx:     'fade',
		timeout: 6000,
		slideExpr: 'dd',
		before: function(curr, next, opts){
			var index = ($(next).index()-1)/2;
			$('.index-middle dl dt').removeClass('active');
			$('.index-middle dl dt:eq('+index+')').addClass('active');
			/*
			if(index==3){
				index_video();
			}
			*/
		}
	});
	$('.index-middle dl dt').click(function(){
		var index=$(this).index()/2;
		$('.index-middle dl').cycle(index);
		if(index==3){
			index_video();
		}
		return false;
	});
}

function lightbox_cycle(){
	$('.lightbox-content-loader').remove();
	$('.lightbox-content').show().cycle({
		fx: 'fade',
		timeout: 5000,
		slideExpr: 'div'
	});
}
function lightbox_content_cycle(id){
	$('.lightbox-content-loader').remove();
	if(id==null){
		val='.wedding .content .cycle_container';
	}else{
		val='.wedding .content '+id+' .cycle_container';
		$('.wedding .content .cycle_container').cycle('destroy');
	}
	$(val).show().cycle({
		fx: 'fade',
		timeout: 5000,
		slideExpr: 'img',
		pager:  val+' .cycle-nav', 
	    // callback fn that creates a thumbnail to use as pager anchor 
	    pagerAnchorBuilder: function(idx, slide) { 
	        return '<li><a href="#"><img src="' + slide.src + '" height="40" /></a></li>'; 
	    }
	});
}
function tab(id){
	$('div.tab-content').hide();
	$(id).css("visibility","visible").show();
	lightbox_content_cycle(id);
}
window.onload = function(){
	if ($('.top-container').length > 0) {
		feature_box();
	}
	if ($('.index-middle').length > 0) {
		feature_box_v2();
	}
	if ($(".lightbox-content").length > 0) {
		lightbox_cycle();
	}
	if ($('.wedding .content .cycle_container').length > 0 && $('.wedding .content .tab-content').length==0) {
		lightbox_content_cycle();
	}
}
$(function(){
	var url=window.location;  
	var anchor=url.hash;
	$('.scroller').jScrollPane({showArrows:true});
	if ($('.top-container').length > 0) {
		$('.top-container dl').after('<div style="height: 353px; width: 995px;" class="loader"><img class="loader_img" src="images/loader1.gif"></div>');
	}
	if ($('.tab-content').length > 0){
		$('.tab a').click(function(){
			$('.tab a').removeClass("active");
			$(this).addClass("active");
			tab($(this).attr("href"));
			return false;
		});
		if(anchor!="")tab(anchor); else tab("#tab1");
	}
	$("a.inline").fancybox({
		'width'				: '500px',
		'height'			: '600px',
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	$("a.lightbox").fancybox({
		'titlePosition'  : 'over',
		'autoScale'	: false
	});
	$("a.gmap").fancybox({
		'width'				: '500px',
		'height'			: '500px',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition'  : 'over'
	});
	$(".top-nav>li").hover(
	  function () {
	    $(this).find("ul").show();
	  },
	  function () {
	    $(this).find("ul").hide();
	  }
	)
	if($('#video').length>0)index_video('OpenDay_ForWeb',235,200,1,1);
});
