$.noConflict();
jQuery(document).ready(function($) {

	// Image rollover
	$('img.hover[src], input.hover[src]').live('mouseover mouseout', function(event) {
		var hovimgend = "_on";
		var pattern = /\.(jpg|jpeg|png|gif)$/;
		var imgsrc = $(this).attr("src");
		var extmatch = imgsrc.match(pattern)[0];
		var matches = imgsrc.match(/hovimgend/);

		if (!matches && event.type == 'mouseover') {
			$(this).attr("src", imgsrc.replace(pattern, hovimgend + extmatch));
		}
		else {
			$(this).attr("src", imgsrc.replace(hovimgend + extmatch, extmatch));
		}

		$(window).bind( 'unload', function(){
				$(this).attr("src", imgsrc.replace(hovimgend + extmatch, extmatch));
		});
	});


	// Global Navigation Menu
	
	
	var pathname = window.location.pathname;
	var splitpath = pathname.split("/");

	for (var i = 0; i < splitpath.length; i++) {
		if (splitpath[i] == "" || splitpath[i] == "index.html") {         
			splitpath.splice(i, 1);
			i--;
		}
	}

	if (pathname == "/inquiry/synthesis.php" || pathname == "/inquiry/doc.php") {         
		$('#nav li.support').addClass('cur');
	}

	$('#nav li').each(function(index) {
		
		if( $(this).attr('class') == splitpath[0]){
			$(this).addClass('cur');
		}		
		if( $(this).attr('class') == splitpath[0] + '-' + splitpath[1] ){
			$(this).addClass('cur');
			$(this).siblings().removeClass('cur');
		}

		var notcur = $(this).not('.cur');

		notcur.find('a').append('<span class="hover"></span>').each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);

			$(this).hover(function () {
				$(this).css('background-position', '0 0');
				$span.stop().fadeTo(300, 1);
			}, function () {
				$(this).css('background-position', '0 0');
				$span.stop().fadeTo(300, 0);
			});
		});
	});



	$(".js_cellHover_01").delegate("td:has('a')", "click hover", function(event){
		if(event.type == 'click'){
		}
		else {
			$(this).toggleClass('hover');
		}
    });


	// Local Navigation Menu
	$('.mod_side_nav ul li:first-child').addClass('first');
	$('.mod_side_nav ul li:last-child').find('span').css('border-bottom', '0');

	var pathname = window.location.pathname;
	var pathname = pathname.replace(/index.html/i, "");
	var naviPlace = $("#side").attr('class');

	$("#side .mod_side_nav ul li a").each(function(){
		if($(this).attr('href') == pathname){
				$(this).closest('li').addClass('cur').parentsUntil('dd').addClass('cur');
		}
		else if(naviPlace){
			var newNaviPlace = naviPlace.split("-");
			var place1 = newNaviPlace[0];
			var place2 = newNaviPlace[1];
			var place3 = newNaviPlace[2];

			if(place1){
				lvl1 = $(".mod_side_nav ul:first-child > li");
				$(lvl1[place1-'1']).addClass("cur");
			}
			if(place2){
				lvl2 = $(".mod_side_nav .cur > ul> li");
				$(lvl2[place2-'1']).addClass("cur");
			}
			if(place3){
				lvl3 = $(".mod_side_nav .cur .cur > ul> li");
				$(lvl3[place3-'1']).addClass("cur");
			}
		}
	});
		

	/* Popup Windows */

	$('a.popup01').live('click', function(){
		newwindow=window.open($(this).attr('href'),'','height=900,width=850,menubar=no,toolbar=no,scrollbars=yes');
		if (window.focus) {newwindow.focus()}
		return false;
	});
	$('a.popup02').live('click', function(){
		newwindow=window.open($(this).attr('href'),'','height=300,width=600,menubar=no,toolbar=no,scrollbars=yes');
		if (window.focus) {newwindow.focus()}
		return false;
	});

});
