if(!MOSS_FW_SESSID) var MOSS_FW_SESSID = "MOSSSESSIDA";
function moss_get_secure(){
	var c = document.cookie;
	var v;
	for(var d=c.split(";"),l=d.length,i=0;i<l;i++){
		if(d[i].indexOf(window.MOSS_FW_SESSID) > -1){
			v = d[i].split(window.MOSS_FW_SESSID+"=")[1];
			break;
		}
	}
	return v;
}

jQuery.scgrph_absolute_path = function(path) {
	var e = document.createElement('span');
	e.innerHTML = '<a href="' + path + '" />';
	return e.firstChild.href;
}

jQuery.fn.scgrph_swapper = function(settings) {
	var regExp = {
		name_NUM_n_o:{
			attach:{regexp:new RegExp("^(.+)_n(\.gif|\.jpg|\.png)$"),callback:"$1_o$2"},
			dettach:{regexp:new RegExp("^(.+)_o(\.gif|\.jpg|\.png)$"),callback:"$1_n$2"}
		},
		name_NUM_o:{
			attach:{regexp:new RegExp("^(.+)(\.gif|\.jpg|\.png)$"),callback:"$1_o$2"},
			dettach:{regexp:new RegExp("^(.+)_o(\.gif|\.jpg|\.png)$"),callback:"$1$2"}
		},
		name_o_NUM:{
			attach:{regexp:new RegExp("^(.+[^o])(_[0-9]+)(\.gif|\.jpg|\.png)$"),callback:"$1_o$2$3"},
			dettach:{regexp:new RegExp("^(.+)_o(_[0-9]+)(\.gif|\.jpg|\.png)$"),callback:"$1$2$3"}
		}
	};
	

	
	var basename = function(path){
		if(path.indexOf("http://") != 0 && path.indexOf("/") != 0) path = jQuery.scgrph_absolute_path(path);
		if(path.indexOf("?")!=-1) path = path.substring(0,path.indexOf("?"));
		if(path.indexOf("#")!=-1) path = path.substring(0,path.indexOf("#"));
		
		if(path.indexOf(window.location.protocol + "//")>-1) return path;
		if(path.charAt(path.length-1) == "/"){
			//if(path.indexOf("/") == 0) path = path.substr(1);
//			path += "index.html";
		}
		return window.location.protocol + "//" + window.location.hostname +  path;
	};
	
	settings = jQuery.extend({
		regexp: "name_o_NUM"
	}, settings || {});


	
	var re = regExp[settings.regexp];
	
	this.
	each(function(){
		var e = jQuery(this);
		var src = e.attr("src").replace(re.dettach.regexp,re.dettach.callback);
		if(basename(window.location.href).indexOf(basename(e.parent().attr("href"))) == 0){
			src = src.replace(re.attach.regexp,re.attach.callback);
			e.addClass("scgrph-cur");
		}
		e.attr({src:src});
	}).
	mouseover(function(){
		if(!jQuery.className.has(this,"scgrph-cur")){
			var e = jQuery(this);
			var src = e.attr("src").replace(re.attach.regexp,re.attach.callback);
			e.attr({src:src});
		}
	}).
	mouseout(function(){
		if(!jQuery.className.has(this,"scgrph-cur")){
			var e = jQuery(this);
			var src = e.attr("src").replace(re.dettach.regexp,re.dettach.callback);
			e.attr({src:src});
		}
	});


	if(settings.force == "active"){
		this.each(function(){
			var e = jQuery(this);
			e.addClass("scgrph-cur").attr({src:e.attr("src").replace(re.attach.regexp,re.attach.callback)}).
			mouseover(function(){}).mouseout(function(){});
		});
	}
	else if(settings.force == "inactive"){
		this.each(function(){
			var e = jQuery(this);
			e.removeClass("scgrph-cur").attr({src:e.attr("src").replace(re.dettach.regexp,re.dettach.callback)});
		});
	}

	
};



jQuery.fn.openWin = function(settings) {
	/*
	settings = jQuery.extend({
	name: "defaultName",
	size: 5,
	global: true
	}, settings || {});
	*/
	/*
	this.click(function(){
		var href = this.href;
		var name = href.split("-").join("_").split("/").join("_").split(".").join("_").split(":").join("_").split("?")[0].split("#")[0];
		var ext = eval("[{"+this.rel+"}]")[0];
		var w = (ext && ext["w"])?ext["w"]:640;
		var h = (ext && ext["h"])?ext["h"]:480;
		var s = (ext && ext["s"])?ext["s"]:0;
		var r = (ext && ext["r"])?ext["r"]:0;
		var win = window.open(href,name,'width=' + w + ',height=' + h + ',scrollbars=' + s+",resizable="+r);
		win.focus();
		return false;
	});
*/
	var sv = navigator.userAgent.split("Safari/")[1];
	if(parseInt(sv) <= 312){
//		$(this).attr("target","_self").click(jQuery.openWinClick);
//		var url = "id"+Math.floor(Math.random()*10000);
//		$(this).before('<span id="'+url+'" />');
//		$(this).attr("title",$(this).attr("href")).attr("href","#"+url).attr("target","_self").click(jQuery.openWinClick)
;	
		$(this).each(
			function(){$(this).get(0).onclick=function(e){jQuery.openWinClick($(e.target).parents("a").get(0));return false;}});
}
	else this.click(jQuery.openWinClick);
};



jQuery.openWinClick = function(o){
	if(o.clientX) o = this;
	if(o.length) o=o[0];
	var href = o.href;//console.log(o);console.log(href);return false;
	if(!href || window.location.href == href) href = o.title;
	
	var name = href.split("-").join("_").split("/").join("_").split(".").join("_").split(":").join("_").split("?")[0].split("#")[0];
	
	var ext;
	if(o.rel) ext = eval("[{"+o.rel+"}]")[0];
	else ext = {};
	var w = (ext && ext["w"])?ext["w"]:640;
	var h = (ext && ext["h"])?ext["h"]:480;
	var s = (ext && ext["s"])?ext["s"]:0;
	var r = (ext && ext["r"])?ext["r"]:0;
	var win = window.open(href,name,'width=' + w + ',height=' + h + ',scrollbars=' + s+",resizable="+r);
	
	win.focus();
	
	return false;
};


(function($){
	$.scgrph_import = function(){
		var callback = Array.prototype.pop.apply( arguments );
		var dict = {};
		var files = arguments;
		for(var i=0,l=files.length;i<l;i++){
			dict[files[i]] = false;
		}
		for(var i=0,l=files.length;i<l;i++){
			var file = $.scgrph_absolute_path(files[i]);
/*			if(jQuery.browser.safari)
				file = files[i];*/
			
			var target = files[i];
			var func = function(target,dict){
				return function(){
					dict[target] = true;
					for(var n=0,m=files.length;n<m;n++){
						if(!dict[files[n]]){return;}
					}
					/*if(!jQuery.browser.safari)*/ callback();
//					else setTimeout(callback,200);
				}
			};
			$.ajax({url:file,dataType:"script",complete:func(target,dict),cache:true});
		}
	};
})(jQuery);

(function($) {
	$.fn.equalizeCols = function(children){
		var child = Array(0);
		if (children) child = children.split(",");
		var maxH = 0;
		this.each(
		  function(i) 
		  {
		    if (this.offsetHeight>maxH) maxH = this.offsetHeight;
		  }
		).css("height", "auto").each(
		  function(i)
		  {
		    var gap = maxH-this.offsetHeight;
		    if (gap > 0)
		    {
		      t = document.createElement('div');
		      $(t).attr("class","fill").css("height",gap+"px");
		      if (child.length > i)
		      {
		        $(this).find(child[i]).children(':last-child').after(t);
		      } 
		      else 
		      {
		        $(this).children(':last-child').after(t);
		      }
		    }
		  }  
		);
	}
})(jQuery);



