
$(document).ready(function() {
	imgRollover();
	imgFade();
	objHeight();
    gridContent();
    imgViewer();
	lightbox();
	linkCheck();
});

$(window).load(function() {
	objHeight();
});




/**********************************************************
* onload */

function addEvent(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false);
	}catch(e){
		elm.attachEvent("on"+listener,fn);
	}
}




/**********************************************************
* linkCheck */

function linkCheck() {
	var check = ['link_name'];
	$('a').each(function(){
		var url = $(this).attr('href');
		for (i in check) {
			if (url.match(check[i])) {
				$(this).replaceWith($(this).html());
			}
		}
	});
}




/**********************************************************
* imgRollover */

function imgRollover() {
	$('img.rollover, input.rollover').not('[src*="_on."],[src*="_over."]').each(function(){
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + '_over' + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function(){
			img.attr('src', src_on);
		},function(){
			img.attr('src', src);
		});
	});
}




/**********************************************************
* imgFade */

function imgFade() {
	$('img.fade').not('[src*="_on."],[src*="_over."]').each(function(){
		$(this).fadeTo(0,1.0);
		$(this).hover(function(){
			$(this).stop();
			$(this).fadeTo(200,0.7);
		},function(){
			$(this).stop();
			$(this).fadeTo(200,1.0);
		});
	});
}




/**********************************************************
* objHeight */

function objHeight() {
	var obj = 0;
	$('.objH').css('height', '');
	$('.objH').each(function(){
		var h = this.offsetHeight;
		if (h > obj) obj = h;
	});
	$('.objH').css('height', obj + 'px').css('display', 'block');
}




/**********************************************************
* gridContent */

function gridContent(){
	$('#gridContent').each(function(){
		$('#gridContent').vgrid({
			easeing: "easeOutQuint",
			useLoadImageEvent: true,
			time: 400,
			delay: 20,
			fadeIn: {
				time: 500,
				delay: 50
			}
		});
	});
}




/**********************************************************
* imgViewer */

function imgViewer(){
	$('#imgViewer div img').each(function(i){
		$(this).attr('id','view' + (i + 1).toString());
		$('#imgViewer div img').css({opacity:'0'}).css({display:'block'});
		$('#imgViewer div img:first').css({opacity:'1'});
	});

	$('#imgViewer ul li').click(function(){
		var connectCont = $("#imgViewer ul li").index(this);
		var showCont = connectCont+1;

		$('#imgViewer div img#view' + (showCont)).siblings().stop().animate({opacity:'0'},1000);
		$('#imgViewer div img#view' + (showCont)).stop().animate({opacity:'1'},1000);

		$(this).addClass('active');
		$(this).siblings().removeClass('active');
		return false;
	});

	$('#imgViewer ul li:not(.active)').hover(function(){
		$(this).stop().animate({opacity:'1'},200);
	},function(){
		$(this).stop().animate({opacity:'0.5'},200);
	});

	$('#imgViewer ul li').css({opacity:'0.5'});
	$('#imgViewer ul li:first').addClass('active');
}




/**********************************************************
* lightbox */

function lightbox() {
	$('a[rel^=lightbox]').lightBox({
		imageLoading:'/common/img/lightbox/lightbox-ico-loading.gif',
		imageBtnPrev:'/common/img/lightbox/lightbox-btn-prev.gif',
		imageBtnNext:'/common/img/lightbox/lightbox-btn-next.gif',
		imageBtnClose:'/common/img/lightbox/lightbox-btn-close.gif',
		imageBlank:'/common/img/lightbox/lightbox-blank.gif',
		fixedNavigation:true
	});
}




/**********************************************************
* openWindow */

function openWindow(winURL,winName,winW,winH) {
	var winFeatures = 'toolbar=no,resizable=no,menubar=no,directories=no,scrollbars=yes,status=no,location=no,width=' + winW + ',height=' + winH + '';
	window.subwin = window.open(winURL,winName,winFeatures);
	window.subwin.focus();
}

