
$(function(){
//======================================================================================
// login window
//======================================================================================
/*
			$(".signin").click(function(e) {          
					e.preventDefault();
					$("fieldset#signin_menu").toggle();
					$(".signin").toggleClass("menu-open");
			});

		$("fieldset#signin_menu").mouseup(function() {
				return false
		});
		$(document).mouseup(function(e) {
				if($(e.target).parent("a.signin").length==0) {
						$(".signin").removeClass("menu-open");
						$("fieldset#signin_menu").hide();
				}
		});	*/
		
//======================================================================================
// スクロール関数
//======================================================================================		
	
	function Scroll(sp){
		$((navigator.userAgent.indexOf("Opera") != -1) ? document.compatMode == "BackCompat" ? "body" : "html" : "html,body").animate({scrollTop:sp},300);
	};

	//ページのトップへ戻る場合
	$('a[href^="#"]').click(function(){
		Scroll(0);
		return false;
	});
	
//======================================================================================
// Mouse hover
//======================================================================================	

	$.auto.hover = {
	init: function() {
		$('IMG.Hover')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
	},
	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
	},
	enter: function() {
		this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
	},
	exit: function() {
		this.src = this.src.replace(/^(.+)_over(\.[a-z]+)$/, "$1$2");
	}
};


});












function Sleep( T ){ 
   var d1 = new Date().getTime(); 
   var d2 = new Date().getTime(); 
   while( d2 < d1+1000*T ){    //T秒待つ 
       d2=new Date().getTime(); 
   } 
   return; 
} 


function openWin(url)
{
	num = Math.floor(Math.random()*1000);
	newwin = 'newwin'+num;
	win = window.open(url,newwin,'toolbar=1,location=0,status=1,menubar=0,scrollbars=yes,resizable=1,width=550px');
	win.focus();
} 




// Initialization

$.auto = {
	init: function() {
		for (module in $.auto) {
			if ($.auto[module].init)
				$.auto[module].init();
		}
	}
};

$(document).ready($.auto.init);


// Auto-hidden elements

$.auto.hide = {
	init: function() {
		$('.Hide').hide();
	}
};


// Mouse hover

$.auto.hover = {

	init: function() {
		$('IMG.Hover')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
	},

	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
	},

	enter: function() {
		this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_over$2");
	},

	exit: function() {
		this.src = this.src.replace(/^(.+)_over(\.[a-z]+)$/, "$1$2");
	}
};


// Auto-submitting SELECTs

$.auto.submit = {
	init: function() {
		$('SELECT.Submit').bind('change', this.on_change);
	},

	on_change: function() {
		if (this.value) this.form.submit();
	}
};


// Auto-selected text in text fields after a label click

$.auto.select = {
	init: function() {
		$('LABEL.Select').each(this.label_action);
		$('INPUT.Select').bind('click', function(){ this.select(); });
	},

	label_action: function() {
		var field = $('#'+this.htmlFor).get(0);
		if (field && field.focus && field.select) {
			$(this).bind('click', function(){ field.focus(); field.select(); });
		}
	}
};


// Switches tabs on click

$.auto.tabs = {

	init: function() {

		$('.Tabs').each(function(){
			var f = $.auto.tabs.click;
			var group = this;
			$('.Tab', group).each(function(){
				this.group = group;
				$(this).click(f);
				$('#'+this.id+'_body').hide();
			}).filter(':first').trigger('click');
		});

	},

	click: function() {
		var tab = $('#'+this.id+'_body').get(0);
		$('.Tab', this.group).each(function(){
			$(this).removeClass('Active');
			$('#'+this.id+'_body').hide();
		});

		$(this).addClass('Active');
		$(tab).show();
		this.blur();

		return false;
	}

};



//======================================================================================
//preload
//======================================================================================
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


//======================================================================================
//label
//======================================================================================
/**
 * IE6でもlabelで囲む記述が有効になるようにする。
 */
$(function(){
  $("label:not([for]):has(:input)").each(function(){
    var input = $(this).children(":input");
    input.attr("id",input.attr("id") || generateId());
    $(this).attr("for", input.attr("id"));
  });
 
  /* 既存のと重複しない一意のIDを生成する関数 */
  function generateId(){
    arguments.callee.count |= 0;
    arguments.callee.count++;
    var id = "generated.input.id$" + arguments.callee.count;
    return document.getElementById(id) == null ? id : generateId();
  }
});


//======================================================================================
// bannerSlider
//======================================================================================
 
(function () {
    $.fn.infiniteCarousel = function () {
        function repeat(str, n) {
            return new Array( n + 1 ).join(str);
        }
        
        return this.each(function () {
            // magic!
            var $wrapper = $('> div', this).css('overflow', 'hidden'),
                $slider = $wrapper.find('> ul').width(9999),
                $items = $slider.find('> li'),
                $single = $items.filter(':first')
                
                singleWidth = $single.outerWidth(),
                visible = Math.ceil($wrapper.innerWidth() / singleWidth / 2),
                currentPage = 1,
                pages = Math.ceil(($items.length / visible) /** 2*/);
                
            /* TASKS */
            
            // 1. pad the pages with empty element if required
            if ($items.length % visible != 0) {
                // pad
                $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
                $items = $slider.find('> li');
            }
            
            // 2. create the carousel padding on left and right (cloned)
            $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
            $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
            $items = $slider.find('> li');
            
            // 3. reset scroll
            $wrapper.scrollLeft(singleWidth * visible);
            
            // 4. paging function
            function gotoPage(page) {
                var dir = page < currentPage ? -1 : 1,
                    n = Math.abs(currentPage - page),
                    left = singleWidth/* * dir * visible * n*/;
                
                $wrapper.filter(':not(:animated)').animate({
                    scrollLeft : '+=' + left,
										opacity: "1"
                }, 500, function () {
                    // if page == last page - then reset position
                    if (page > pages) {
                        $wrapper.scrollLeft(singleWidth /* visible*/);
                        page = 1;
                    } else if (page == 0) {
                        page = pages;
                        $wrapper.scrollLeft(singleWidth /** visible * pages*/);
                    }
                    
                    currentPage = page;
                });
            }
            
            // 5. insert the back and forward link
            //$wrapper.after('<a href="#" class="arrow back">&lt;</a><a href="#" class="arrow forward">&gt;</a>');
            
            // 6. bind the back and forward links
            $('a.back', this).click(function () {
                gotoPage(currentPage - 1);
                return false;
            });
            
            $('a.forward', this).click(function () {
                gotoPage(currentPage + 1);
                return false;
            });
            
            $(this).bind('goto', function (event, page) {
                gotoPage(page);
            });
            
            // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
            $(this).bind('next', function () {
							if($(this).attr("id") == "delay"){
								setTimeout(function () {
        					gotoPage(currentPage + 1);
    						}, 3000);	
                
							}else{
								gotoPage(currentPage + 1);
							}
            });
        });
    };
})(jQuery);
 

