﻿$(document).ready(function() {
	// search form validatin check
	$('#searchForm input').focus(function() {
		var q = $('#searchForm input').attr('value');
		
		if(q == '输入关键词后请按回车键。')
			$('#searchForm input').attr('value', '');
	});
	
	$('#searchForm input').blur(function() {
		var q = $('#searchForm input').attr('value');
		
		if(q == '')
			$('#searchForm input').attr('value', '输入关键词后请按回车键。');
	});
	$('#searchForm input').keypress(function(event) {
		var q = $('#searchForm input').attr('value');

		if(event.keyCode == '13'){
			if(q == ''){
				alert('\n输入关键词后请按回车键。');
			}
			else
				$('#searchForm').submit();
		}
	});
	
	// gnb
	$('.gnb li a').mouseover(function() {
		var gnbName = $(this).attr('rel');
		if(gnbName != 'more'){
			if($('#header div.' + gnbName).css('display') == 'none'){
				$('#header div.gnbSub').css('display', 'none');
				$('#header div.' + gnbName).css('display', 'block');
			}
		} else {
			if($('#header div.more').css('display') == 'none')
				$('#header div.gnbSub').css('display', 'none');
		}
		
	});
	$('.gnb li a.more').click(function() {
		if($('#header div.more').css('display') == 'none') 
			$('#header div.more').css('display', 'block');
		else
			$('#header div.more').css('display', 'none');
	});

	// galleryview control
	$('#galleryView').galleryView({
		panel_width: 278,
		panel_height: 185,
		frame_width: 43,
		frame_height: 37,	
		overlay_opacity: 0.85,
		pause_on_hover: true
	});
});


function flashWrite(url,w,h,id,bg,win){
	// 플래시 코드 정의
	var flashStr=
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
	"<param name='movie' value='"+url+"' />"+
	"<param name='wmode' value='"+win+"' />"+
	"<param name='menu' value='false' />"+
	"<param name='quality' value='high' />"+
	"<param name='bgcolor' value='"+bg+"' />"+
	"<embed src='"+url+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>";

	// 플래시 코드 출력
	document.write(flashStr);
}

String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.replaceAll = function(str1, str2){
	var temp_str = "";
	if (this.trim() != "" && str1 != str2){
		temp_str = this.trim();
		while (temp_str.indexOf(str1) > -1){
			temp_str = temp_str.replace(str1, str2);
		}
	}
	return temp_str;
}

String.prototype.startWith = function(pattern){
    return this.indexOf(pattern) === 0;
  }

String.prototype.endsWith = function(pattern){
    var d = this.length - pattern.length;
    return d >= 0 && this.lastIndexOf(pattern) === d;
}

