// jquery onload
$(function(){
	window.onload = function(){
		//chaser sidebar
		if($("#sidenavi").size()>0){
			var $sidebar   = $("#sidenavi"),
				$window    = $(window),
				offset     = $sidebar.offset(),
				topPadding = 15;
	
			$window.scroll(function() {
				if ($window.scrollTop() > offset.top) {
					$sidebar.stop().animate({
						marginTop: $window.scrollTop() - offset.top + topPadding
					});
				} else {
					$sidebar.stop().animate({
						marginTop: 0
					});
				}
			});
		}
		if($("#floatcart").size()>0){
			var $sidebar   = $("#floatcart"),
				$window    = $(window),
				offset     = $sidebar.offset(),
				topPadding = 15;
	
			$window.scroll(function() {
				if ($window.scrollTop() > offset.top) {
					$sidebar.stop().animate({
						marginTop: $window.scrollTop() - offset.top + topPadding
					});
				} else {
					$sidebar.stop().animate({
						marginTop: 0
					});
				}
			});
		}
		
		//smooth scroll
		$('a[href^=#]').click(function() {
		  var speed = 400;
		  var href= $(this).attr("href");
		  var target = $(href == "#" || href == "" ? 'html' : href);
		  var position = target.offset().top;
		  $($.browser.safari ? 'body' : 'html').animate({scrollTop:position}, speed);
		  return false;
		});
		 
		//fancybox
		if($('#point_check').size()>0){
			$('#point_check a').fancybox({type:'iframe',width:370,height:250});
		}
		if($('#courceImg').size()>0){
			$('#courceImg a').fancybox({type:'iframe',width:1200,height:700});
			$('#courceImg2 a').fancybox({type:'iframe',width:1200,height:700});
		}
		if($('.cpoint').size()>0){
			$('.cpoint a').fancybox();
		}
		
		//weather_unit
		var weatherpreload1 = $('<img src="assets/images/system/top/weather_unit5_1.png">');
		var weatherpreload2 = $('<img src="assets/images/system/top/weather_unit5_2.png">');
		var weatherpreload3 = $('<img src="assets/images/system/top/weather_unit5_3.png">');
		var weatherpreload4 = $('<img src="assets/images/system/top/weather_unit5_4.png">');
		$('#weather_unit3 ul#w_switch li').css('cursor','pointer');
		$('#weather_unit3 #w_switch li').click(function(){
			var id = $(this).attr('class').replace('p','');
			var wbase = $('#weather_unit3');
			$('#page_list>li').each(function(){
				var pid = $(this).attr('class').replace('c','');
				(pid == id) ? $(this).show() : $(this).hide();
			});
			wbase.css('background-image','url(assets/images/system/top/weather_unit5_'+id+'.png)');
		});
		$('#weather_unit3 #page_list>li').eq(0).show();
		
	}
});
