/*
 * project.js
 * 
 * Copyright (c) 2010 IMG SRC Inc.
 *
 */

var Skytree = {
	
	reqJS: new Array(
		'shared/js/lib/jquery.easing.1.3.js',
		'shared/js/lib/jquery.cookie.js',
		'shared/js/functions.js'
	),
	
	// loadJS
	loadJS: function(jsURL){
		document.write('<script type="text/javascript" charset="UTF-8" src="'+jsURL+'"></script>');
	},
	
	// distributesOS
	distributesOS:function(){
		var u = 'unknown';
		var os = (/(win|mac|linux|sunos|solaris|iphone|ipod|ipad)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris');
		return os;
	},
	
	// checkBrowser
	checkBrowser:function(){
		//opera:this.userAgentIs('Opera'),
		//chrome:this.userAgentIs('Chrome'),
		//firefox:this.userAgentIs('Firefox'),
		//safari:this.userAgentIs('Safari'),
		//ie:this.userAgentIs('MSIE');
		ie6:this.userAgentIs('MSIE 6');
	},
	
	// setScroll
	setScroll:function(){
		if(!$('a[href^="#"]')) return;
		var durationTime = 1000;
		var easingType = 'easeInOutCirc';
		$('a[href^="#"]').click(function(){
			var target = $(this).attr('href');
			if(target == "#"){
				$(this).blur();		
				$('html, body').animate({scrollTop:0}, durationTime, easingType);
				return false;
			}
			return false;
		});
	},
	
	// setTargetBlank
	setTargetBlank:function(){
		$('a[rel="external"][href]').attr('target', '_blank');	
	},
	
	// rollover
	baseInitRollovers:function(){	
		var overPath = "_on";
		var aImages = $('img.imgover, input.imgover');
		
		for(var i=0; i<aImages.length; i++)
		{
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);	
			var hsrc = src.replace(ftype, overPath + ftype);
			aImages[i].setAttribute('hsrc', hsrc);
			aImages[i].setAttribute('defsrc', src);
			aImages[i].onmouseover = function(){this.setAttribute('src', this.getAttribute('hsrc'));}
			aImages[i].onmouseout = function()	{this.setAttribute('src', this.getAttribute('defsrc'));}
		}
	},	
	
	// userAgentIs
	userAgentIs:function(ua){
		return navigator.userAgent.indexOf(ua) > 0;
	},
	
	// checkUA
	checkUA:function(){
		$("body").attr("id", this.distributesOS());
	},
	
	// exsistID
	exsistID:function(str){
		//str.replace('#', '');
		return document.getElementById(str);	
	},
	
	
	/*
	init
	*/
	init: function(){		
			
		jQuery.each(this.reqJS, function() {
			Skytree.loadJS(this);
		});
		
		/*DOM Ready Event*/
		jQuery(document).ready(function(){
			Skytree.checkUA();
			Skytree.setScroll();
			Skytree.setTargetBlank();
			Skytree.baseInitRollovers();
			Skytree.mainInit();
		});
		
	}
};

Skytree.init();

// resize
$(window).bind('resize', function(){Skytree.onResizeMod()});
