/* ---------------------------------------------------------------
	
	COMMON.JS 
		
--------------------------------------------------------------- */
/*
	EXTEND LIBRARY
*/
jQuery.extend();
jQuery.fn.extend();

var rootPath = function(){
	return jQuery('script#coreJS')[0].src.split('script/js')[0];
}

/*
	AUTOMATION
*/
//FUNCTION initRollOvers
function initRollOvers(){
	if(!document.getElementById) return;

	var preImgArr = new Array();

	$('img.ahover').each(function(){
		var src = $(this).attr('src');
		var isov = src.substring(0,src.lastIndexOf('.'));
		if( isov.substring(isov.length-3, isov.length) != "_ov"
		 && isov.substring(isov.length-3, isov.length) != "_on"
		 && isov.substring(isov.length-4, isov.length) != "_off"
		){
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_ov'+ftype);
			var dsrc = src;
			$(this).attr('hsrc', hsrc);
			$(this).attr('dsrc', dsrc);

			preImgArr.push(new Image());
			preImgArr[preImgArr.length-1].src = hsrc;

			$(this).bind('mouseover', function(e){
				$(this).attr('src', $(this).attr('hsrc'));
			});
			$(this).bind('mouseout', function(e){
				$(this).attr('src', $(this).attr('dsrc'));
			});
			if ($.browser.safari) {
				$(this).bind('click', function(e){
					$(this).attr('src', $(this).attr('dsrc'));
				});
			}
		}
	});
}
//FUNCTION smoothScroll
var actX;
var actY;
var tarY = 0;
var tarX = 0;
var scrollInt;
var smoothScroll = function () {
	jQuery('a').each(function(){
		var anc = this.href.split('#')[1];
		if( /#/.test(this.href)  && this.href.match(location.href) && jQuery('#'+anc)[0] ){
			this.href="javascript:void(0);";
			jQuery(this).bind('click', function  (){
				tarX = (jQuery(document).width() > jQuery('#'+anc).position().left + jQuery(window).width())
					? jQuery('#'+anc).position().left
					: jQuery(document).width() - jQuery(window).width();
				tarY = (jQuery(document).height() > jQuery('#'+anc).position().top + jQuery(window).height())
					? jQuery('#'+anc).position().top
					: jQuery(document).height() - jQuery(window).height();
			  actX = jQuery(document).scrollLeft();
			  actY = jQuery(document).scrollTop();
				clearInterval(scrollInt);
				scrollInt = setInterval('setScroll()', 20);
			});
		}
	});
}
function setScroll(){
	actY += (tarY - actY) / 6;
	actX += (tarX - actX) / 6;
	if(Math.abs(tarX - actX) < 2 && Math.abs(tarY - actY) < 2){
		clearInterval(scrollInt);
	}
	scrollTo( Math.round(actX), Math.round(actY));
}

function blankToPop () {
	jQuery('a.commonPop').each(function(){
		$(this).removeAttr("target");
		$(this).attr('popURL', this.href);
		( $(this).attr("rel") ? "" : $(this).attr("rel","") );
		this.href = "javascript:;";
		$(this).click(function () {
			eval("commonPop('"+$(this).attr("popURL")+"',"+$(this).attr("rel")+")");
		});
	});
}

/*
	USER FUNCTION
*/
//FUNCTION commonPop
//pFile = popup File
//pWidth = popup Width [optional]
//pHeight = popup Height [optional]
//pStatus = popup Features[optional]
function commonPop(pFile, pWidth, pHeight,pStatus){
	//var fName = pFile.substring(pFile.lastIndexOf('/')+1, pFile.length);
	var wName = "";
	if(pWidth == null){ pWidth = 700}
	if(pHeight == null){ pHeight = 600}
	if(pStatus == null){ pStatus = 'yes';}
	if(pWidth > screen.availWidth){
		pWidth = screen.availWidth;
		pStatus = 'yes';
	}
	if(pHeight > screen.availHeight-50){
		pHeight = screen.availHeight-50;
		pStatus = 'yes';
	}
	var wFeatures= 'menubar=no,scrollbars='+pStatus+',resizable='+pStatus+',width='+pWidth+',height='+pHeight;
	void(window.open(pFile, wName, wFeatures));
}

/*
	SET
*/
jQuery(document).ready(function(){
	initRollOvers();
	smoothScroll();
});

/*
	STYLE SWITCH
*/
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

/*
	TEXT
*/
function SumPadding1(){
	var TextWidth1 = $("#Title1").width();
	$('#Cap1').css('padding-left',TextWidth1);
	};
	setInterval(SumPadding1,1);
function SumPadding2(){
	var TextWidth2 = $("#Title2").width();
	$('#Cap2').css('padding-left',TextWidth2);
	};
	setInterval(SumPadding2,1);
function SumPadding3(){
	var TextWidth3 = $("#Title3").width();
	$('#Cap3').css('padding-left',TextWidth3);
	};
	setInterval(SumPadding3,1);
function SumPadding4(){
	var TextWidth4 = $("#Title4").width();
	$('#Cap4').css('padding-left',TextWidth4);
	};
	setInterval(SumPadding4,1);
function SumPadding5(){
	var TextWidth5 = $("#Title5").width();
	$('#Cap5').css('padding-left',TextWidth5);
	};
	setInterval(SumPadding5,1);
function SumPadding6(){
	var TextWidth6 = $("#Title6").width();
	$('#Cap6').css('padding-left',TextWidth6);
	};
	setInterval(SumPadding6,1);
function SumPadding7(){
	var TextWidth7 = $("#Title7").width();
	$('#Cap7').css('padding-left',TextWidth7);
	};
	setInterval(SumPadding7,1);
function SumPadding8(){
	var TextWidth8 = $("#Title8").width();
	$('#Cap8').css('padding-left',TextWidth8);
	};
	setInterval(SumPadding8,1);
function SumPadding9(){
	var TextWidth9 = $("#Title9").width();
	$('#Cap9').css('padding-left',TextWidth9);
	};
	setInterval(SumPadding9,1);
function SumPadding10(){
	var TextWidth10 = $("#Title10").width();
	$('#Cap10').css('padding-left',TextWidth10);
	};
	setInterval(SumPadding10,1);
function SumTop(){
	var MyHeight = $(".sum-box_l").height();
	$('.sum-box_l').css('margin-top',-(MyHeight)/2);
	};
	setInterval(SumTop,1);
