/**
 * @author masa
 */
$(function(){
	// big menu is locimg variable
	var host = location.href.match(/^http[s]*:\/\/[a-zA-Z0-9.-]+\//)[0]
	var headtmp = host + "header_template.html"
	var header = $('#header')
	
	$('img').each(function(){
		if($(this).attr('src').match('_off')){
			var img = $(this)
			// if off, set hover event
			img.hover(function(){
				if($(this).attr('src').match('_off')){
				$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
			}},function(){
				if($(this).attr('src').match('_on')){
					jQuery(this).attr("src", jQuery(this).attr("src").replace("_on.", "_off."));
				}
			})
		}
	})

	$.get(headtmp,function(response){
		header.html(response)
		var menus = $("#headmenu > li")
		// rollover event
		if(locimg){
			menus.each(function(i,el){
				if(locimg != $(this).attr('id')){
					$(this).hover(function(){
						var src = $('img:eq(0)', this).attr('src')
						$('img:eq(0)', this).attr('src', src.replace('_off', '_on'))
						if ($("ul", el).length) 
							$("ul", el).show();
					},function(){
						var src = $('img:eq(0)', this).attr('src')
						$('img:eq(0)', this).attr('src', src.replace('_on', '_off'))
						if ($("ul", el).length) 
							$("ul", el).hide();
					})
				} else {
					var src = $('img:eq(0)', this).attr('src')
					$('img:eq(0)', this).attr('src', src.replace('_off', '_on'))
					$(this).hover(function(){
						if ($("ul", el).length) 
							$("ul", el).show();
					},function(){
						if ($("ul", el).length) 
						$("ul", el).hide();
					})
				}
			})				
		} else {
			menus.each(function(i, el){
				$(el).hover(function(){
					var src = $('img:eq(0)', this).attr('src')
					$('img:eq(0)', this).attr('src', src.replace('_off', '_on'))
					if ($("ul", el).length) 
						$("ul", el).show();
				}, function(){
					var src = $('img:eq(0)', this).attr('src')
					$('img:eq(0)', this).attr('src', src.replace('_on', '_off'))
					if ($("ul", el).length) 
						$("ul", el).hide();
				});
			})
		}
	})
	
	if($("#footer").length){
		var foottmp = host + "footer_template.html"
		var footer = $('#footer')
		$.get(foottmp,function(response){
			footer.html(response)
		})
	}		
	
	
	
	
	 
})
