
(function($){ $.fn.fixedPosition = function(options){

    var defaults = {
	  vpos: null,    // posible values: "top", "middle", "bottom". if it is null the original position is taken
	  hpos: null     // posible values: "left", "center", "right". if it is null the original position is taken
	};
	
    var options = $.extend(defaults, options);
	
	return this.each(function(index) {
		
		
		var $this = $(this);
		$this.css("position","absolute");
		
		if(options.vpos === "top"){
		    $this.css("top","0");
		}
		else if(options.vpos === "middle"){
		    $this.css("top",((parseInt($(window).height())/2)-($(this).height()/2))+"px");
		}
		else if(options.vpos === "bottom"){
		    $this.css("bottom","0");
		}
		
		if(options.hpos === "left"){
		    $this.css("left","0");
		}
		else if(options.hpos === "center"){
		    $this.css("left",((parseInt($(window).width())/2)-($(this).width()/2))+"px");
		}
		else if(options.hpos === "right"){
		    $this.css("right","0");
		}
		
		var top = parseInt($this.offset().top);
		var left = parseInt($this.offset().left);
		$(window).scroll(function () {
			$this.css("top",top+$(document).scrollTop()).css("left",left+$(document).scrollLeft());
		});
	});

  
}})(jQuery);

;(function($){
	
	$.fn.mask = function(label){
		var cHeight = this.height();
		this.unmask();
		
		if(this.css("position") == "static" || this.css("position") == "") {
			this.addClass("masked-relative");
		}
		
		this.addClass("masked");

		var maskDiv = $('<div class="loadmask" ></div>');
		//var wrapDiv = $('<div style="position : static;zoom:1;"></div>');
		//auto height fix for IE
		if($.browser.msie){
			var h = this.height() + parseInt(this.css("padding-top")) + parseInt(this.css("padding-bottom"));
			if (h < cHeight)
			{
				h = cHeight;
			}
			var w = this.width() + parseInt(this.css("padding-left")) + parseInt(this.css("padding-right")) ;
			maskDiv.css('height',h+"px");
			maskDiv.css('width',w+"px");
			maskDiv.css('left',"0px");
			maskDiv.css('top',"0px");
			//maskDiv.height();
			//maskDiv.width(w);
		}else {

		}

		//fix for z-index bug with selects in IE6
		if(navigator.userAgent.toLowerCase().indexOf("msie 6") > -1){
			this.find("select").addClass("masked-hidden");
		}
	    /*
		if (this.height() <= 24)
		{
			var hh = 24;
			if (cHeight > 24)
			{
				hh = cHeight;
				//this.height(cHeight);
			}
			//this.height(hh);
			maskDiv.height(hh);
			maskDiv.css('height',hh+'px');
			
		}
		
		maskDiv.css('left',"0px");
		maskDiv.css('top',"0px");
		
        */
		this.prepend(maskDiv);
		//wrapDiv.append(maskDiv);
		//this.prepend(wrapDiv);
		//this.append(maskDiv);
		
		
		if(typeof label == "string") {
			var maskMsgDiv = $('<div class="loadmask-msg" style="display:none;"></div>');
			maskMsgDiv.append('<div>' + label + '</div>');
			this.append(maskMsgDiv);
			
			//calculate center position
			maskMsgDiv.css("top", Math.round(this.height() / 2 - (maskMsgDiv.height() - parseInt(maskMsgDiv.css("padding-top")) - parseInt(maskMsgDiv.css("padding-bottom"))) / 2)+"px");
			maskMsgDiv.css("left", Math.round(this.width() / 2 - (maskMsgDiv.width() - parseInt(maskMsgDiv.css("padding-left")) - parseInt(maskMsgDiv.css("padding-right"))) / 2)+"px");
			
			maskMsgDiv.show();
		}
		
	};
	
	/**
	 * Removes mask from the element.
	 */
	$.fn.unmask = function(label){
		this.find(".loadmask-msg,.loadmask").remove();
		this.removeClass("masked");
		this.removeClass("masked-relative");
		this.find("select").removeClass("masked-hidden");
	};
 
})(jQuery);


(function($) {
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove.cluetip",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove.cluetip",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.bind('mouseover.cluetip', handleHover).bind('mouseout.cluetip', handleHover);
	};
})(jQuery);

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // NOTE Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/*TextArea Resize*/
(function($){var textarea,staticOffset;var iLastMousePos=0;var iMin=32;var grip;$.fn.TextAreaResizer=function(){return this.each(function(){textarea=$(this).addClass('processed'),staticOffset=null;$(this).wrap('<div class="resizable-textarea"><span></span></div>').parent().append($('<div class="grippie"></div>').bind("mousedown",{el:this},startDrag));var grippie=$('div.grippie',$(this).parent())[0];grippie.style.marginRight=(grippie.offsetWidth-$(this)[0].offsetWidth)+'px'})};function startDrag(e){textarea=$(e.data.el);textarea.blur();iLastMousePos=mousePosition(e).y;staticOffset=textarea.height()-iLastMousePos;textarea.css('opacity',0.25);$(document).mousemove(performDrag).mouseup(endDrag);return false}function performDrag(e){var iThisMousePos=mousePosition(e).y;var iMousePos=staticOffset+iThisMousePos;if(iLastMousePos>=(iThisMousePos)){iMousePos-=5}iLastMousePos=iThisMousePos;iMousePos=Math.max(iMin,iMousePos);textarea.height(iMousePos+'px');if(iMousePos<iMin){endDrag(e)}return false}function endDrag(e){$(document).unbind('mousemove',performDrag).unbind('mouseup',endDrag);textarea.css('opacity',1);textarea.focus();textarea=null;staticOffset=null;iLastMousePos=0}function mousePosition(e){return{x:e.clientX+document.documentElement.scrollLeft,y:e.clientY+document.documentElement.scrollTop}}})(jQuery);

/***************************************
 * Util Functions
 ***************************************/
 
Function.prototype.defaults = function()
{
  var _f = this;
  var _a = Array(_f.length-arguments.length).concat(
    Array.prototype.slice.apply(arguments));
  return function()
  {
    return _f.apply(_f, Array.prototype.slice.apply(arguments).concat(
      _a.slice(arguments.length, _a.length)));
  }
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

String.prototype.getNum = function() {
	var str= this.match(/\d+$/);
	if (str == null) return "";
	else return str;
}

String.prototype.getPreNum = function() {
	var str = this.match(/^\d+/);
	if (str == null) return "";
	else return str;
}

String.prototype.isNumber = function() { 
  var re = /^[0-9]+$/;
	return re.test(this); 
	
}
String.prototype.isPhone = function() { 
	var re = /^[\-0-9]+$/;
	return re.test(this); 
}

String.prototype.isAlphaNumeric = function() {
	var AlphaNumeric;				
	AlphaNumeric = /^\w+$/;
	return AlphaNumeric.test(this);
}

String.prototype.isSpecial = function() {
	  var limit_char = /[~!\#$^&*\=+|:;?"<,.>']/;
    return limit_char.test(this);
}

String.prototype.hasSpace = function() {
	var fmt = /\s+/g;
	return fmt.test(this);
}

String.prototype.formatPrice = function() 
{
	var nStr = this;
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function loadJavascript(file) {
	var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", file);
  if (typeof (fileref)!="undefined")
  		document.getElementsByTagName("head")[0].appendChild(fileref);
}

function seed(len) {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = len;
	var randomstring ="";

	for (var i=0; i < len;i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}

	return randomstring;
}


var queryParse = function(q) {
	
	 if (q.indexOf("?")) {
		 var qs = q.split("?");
		 q = qs[1];
	 }

	 var r = {};
     q = q.replace(/^\?/,''); // remove the leading ?
     q = q.replace(/\&$/,''); // remove the trailing &
     jQuery.each(q.split('&'), function(){
                 var key = this.split('=')[0];
                 var val = this.split('=')[1];
                 // convert floats
                 if(/^[0-9.]+$/.test(val))
                         val = parseFloat(val);
                 // ingnore empty values
                 if(val)
                         r[key] = val;
     });
     return r;
}; 

function forcego(url) {
	go(url);
}

function go(url) {
	onLoading();
	setTimeout(function()
	{
    window.location = url;
	}, 0);

}

function gonew(url) {
	
	setTimeout(function()
	{
    window.open(url);
	}, 0);

}


function anchor(name) {
	location.href = "#"+name;
}


var getFileName = function(path) {
    var b = path.replace(/^.*[\/\\]/g, '');

	  var suffix = getFileExt(b);
    if (suffix != "" &&  b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length-1);
    }
	return b.toLowerCase();

}.defaults("");


var getFileExt = function(filename) 
{ 

 	if( filename.length == 0 ) return ""; 
 	var dot = filename.lastIndexOf("."); 
	if( dot == -1 ) return ""; 
 	var extension = filename.substr(dot+1,filename.length); 
  return extension.toLowerCase(); 
} 


var getRSS = function(blog) {
	
	/* this is a specific function only to korean blogs */
	var rss = "";
	blog = blog.toLowerCase();
	if (blog.indexOf("http://") < 0){
		blog = "http://"+blog;
	}
	if (blog.charAt(blog.length-1) == "/") {
		blog = blog.substring(0,blog.length-1);
	}

	if (blog.indexOf("naver.com") > -1) {
		var id = sa_getfilename(blog);
		rss = "http://blog.rss.naver.com/"+id+".xml";
	}else if (blog.indexOf("tistory.com") > -1) {

		rss = blog + "/rss";
	}else if (blog.indexOf("egloos.com") > -1) {
		var id = blog.slice(blog.indexOf("http://")+7,blog.indexOf("."));
		rss = "http://rss.egloos.com/blog/"+id;
	}else if (blog.indexOf("daum.net") > -1) {
		var id = sa_getfilename(blog);
		rss = "http://blog.daum.net/xml/rss/"+id+"/view";

	}else rss = "";

	return rss;
}

var createForm = function(id,data,action,method) {
	var form = $('<form method="POST" name="' + id + '" id="' + id + '" action="' + action + '" method="' + method + '" ></form>');	
	$(form).appendTo('body');

	$.each(data, function(key, val) {
        $('<input type="hidden" name="'+key+'" value="'+val+'" />').appendTo(form);
    });

	return form;

}.defaults('','GET');

var getCheckedFormValue = function(radioObj) {
	
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}



/*****************************************************
 * Ajax Related
 *****************************************************/

 
var defaultCallback = function(str) {
	ovAlert('',STR_LOAD_SUCCESS);
};

var xmlDoc = function(xmlstr) {
	
  if (window.ActiveXObject)
  {
  	var doc=new ActiveXObject("Microsoft.XMLDOM");
  	doc.async="false";
  	doc.loadXML(xmlstr);
  }
  else
  {
  	var parser=new DOMParser();
  	var doc=parser.parseFromString(xmlstr,"text/xml");
  }

  return doc;

}.defaults("");

function getResponse(rtext) {
	
	rtext = rtext.replace(/\x5B/g,"<");
	rtext = rtext.replace(/\x5D/g,">");
	
	var item = rtext.slice(rtext.indexOf("<snugitem>"),rtext.indexOf("</snugitem>"));
	
	if (item == "") {
		return new Array("401","format error",rtext);
	}
	
	
	var code = item.slice(item.indexOf("<code>")+6,item.indexOf("</code>"));
	var status = item.slice(item.indexOf("<status>")+8,item.indexOf("</status>"));
	var message = item.slice(item.indexOf("<message>")+9,item.indexOf("</message>"));

	if (code == "" || status == "" ) {
		return new Array("402","format error",rtext);
	}
	
	return new Array(code,status,message);
}





var upload = function(url , fid , fileh , spcallback) {
	
	var f = $("#"+fid);
	var str = f.serialize();
	
	if (str == "") {
		offLoading();
		ovAlert('',STR_WRONG_POST_DATA);
		return false;
	}



	var callback = function(r,s) {
	
		offLoading();

		if (s == "success" && typeof(r) != "undefined") {
			var responseA = getResponse(r);
					
			if (responseA[1] == "ok") {
				
				if (spcallback != null)
					spcallback(responseA[2]);

			}else {
				offLoading();
				ovAlert(responseA[2],STR_RESPONSE_ERROR);
			}
		}
		else {
			offLoading();
			//ovAlert('',STR_NETWORK_ERROR);
		}
		
	};


	
	
	onLoading();
	
	var realdata = f.serializeArray();
	
	

	jQuery.ajaxFileUpload({  
        url: url,  
        data: realdata, 
				secureuri:false,
				fileElementId: fileh,	
				dataType : "text",
        timeout: 180000,  
        success: function(r, s) {  
			
						callback(r,s);
        },  
        error: function(r, s, e) {  
						callback(e,"error");
        }  
    });  
	
};

var on_post_processing = false;
var post = function(url , fid , spcallback , raw) {
	
	if (on_post_processing) return;
	on_post_processing = true;
	var f = $("#"+fid);
	var str = f.serialize();
	

	if (str == "") {
		offLoading();
		ovAlert('',STR_WRONG_POST_DATA);
		return false;
	}

	var callback = function(r,s) {
		
		offLoading();
		on_post_processing = false;

		if (s == "success" && typeof(r) != "undefined") {
			
			if (raw && spcallback != null) {
			
				if (r == null || typeof(r) == "undefined") r = "";
				spcallback(r);
				return ;
			}

			var responseA = getResponse(r);
			
			
			if (responseA[1] == "ok") {
				
				if (spcallback != null  && !raw)
					spcallback(responseA[2]);
			}else {
				offLoading();
				ovAlert(responseA[2],STR_RESPONSE_ERROR);
			}
		}
		else {
			offLoading();
			//ovAlert(''.STR_NETWORK_ERROR);
		}
		
	};

	
	onLoading();

	if (url.indexOf("?") == -1)
		url = url+"?stamp="+seed(4);
	else
		url = url+"&stamp="+seed(4);
	
	$.post( url, str , callback );
	
}.defaults(false);


var get = function(url,spcallback,quiet,raw) {
	
	var ourl  = url;
	var callback = function(r,s) {
		
		if (!quiet)  {
			offLoading();
		}


		if (s == "success" && typeof(r) != "undefined") {
			

			if (raw && spcallback != null) {
			
				if (r == null || typeof(r) == "undefined") r = "";
						spcallback(r);

				if (typeof(pageTracker) != "undefined" && pageTracker != null ) {
						pageTracker._trackPageview(ourl); 
				}

				return ;
			}

			var responseA = getResponse(r);
			
			if (responseA[1] == "ok") {
				
				if (spcallback != null && !raw)
					spcallback(responseA[2]);

				if (typeof(pageTracker) != "undefined"  && pageTracker != null ) {
						pageTracker._trackPageview(ourl); 
				}


			}else {
				offLoading();
				ovAlert(responseA[2],STR_RESPONSE_ERROR);
				
				
			}
		}
		else {
			if (!raw) {
				offLoading();
				//ovAlert('',STR_NETWORK_ERROR);
			}else {
				if (spcallback != null) spcallback("error");
			}
		}
		
	};

	if (!quiet)  {
		onLoading();
	}

	if (url.indexOf("?") == -1)
		url = url+"?stamp="+seed(4);
	else
		url = url+"&stamp="+seed(4);

	$.get( url, callback );


}.defaults(false,false);


var load = function(obj,url,spcallback , quiet) {
	
	var ourl  = url;
	var callback = function(r,s,x) {
		
		$(obj).unmask();
		//offloading
		//if (!quiet) offLoading();

		if (s == "success" && typeof(r) != "undefined") {
			if (spcallback != null) {
				spcallback(r);
			}

			if (typeof(pageTracker) != "undefined"  && pageTracker != null ) {
				pageTracker._trackPageview(ourl); 
			}
		}
		else {
			
			ovAlert('',r);

		}
	};
	
	//if (!quiet) onLoading();
	
	if (url.indexOf("?") == -1)
		url = url+"?stamp="+seed(4);
	else
		url = url+"&stamp="+seed(4);
	
	setTimeout(function() {
		
		$(obj).css("min-height","80px");
		$(obj).mask('Loading...');
		setTimeout(function() {
			$(obj).load(url,'',callback);
		},300);

	},0);


}.defaults(false);



var focusTextElement = function(ele , val)  {
	
	var tval = $(ele).val();
	if (tval == val || tval == "") {
		$(ele).val("");
	}
	
}.defaults('');

var blurTextElement = function(ele , val)  {
	var tval = $(ele).val();
	if (tval == val || tval == "") {
		$(ele).val(val);
	}
	
}.defaults('');

function enterKeyUpHadler(e) {
	var keycode;

	if (!e) var e = window.event;
	if (e.keyCode) keycode = e.keyCode;
	else if (e.which) keycode = e.which;
	
	if (keycode != 13) return;
	
	if (arguments.length > 1) {
		var func = arguments[1];
		var args = new Array();
		for (var i = 2; i < arguments.length; i++)
	  {
	     args[args.length] = arguments[i];
	  }
	  
	  func.apply(func,args);
	 }
			
}





/**************************************
 * UI Functions
 **************************************/


var syncHeight = function(obj1,obj2) {
			var h1 = $(obj1).height();
			var h2 = $(obj2).height();	
			var h = (h1 > h2 ? h1 : h2);
			$(obj1).height(h);
			$(obj2).height(h);
};

var cycleList = function(tabs, output, options) {
		
		var timer = 1;
		var options			= options || {}; 
		var total_items		= tabs.length;
		var visible_item	= options.start_item || 0;
		var self = this;
		
		
		function slide(nr) {
			if (typeof nr == "undefined") {
				nr = visible_item + 1;
				nr = nr >= total_items ? 0 : nr;
			}

			tabs.removeClass('current').filter(":eq(" + nr + ")").addClass('current');

			output.stop(true, true).filter(":visible").fadeOut();
			output.filter(":eq(" + nr + ")").fadeIn(function() {
				visible_item = nr;	
				loadAjaxContent(this);	
			});
		}
		
		var loadAjaxContent = this.loadAjaxContent = function (obj) {
			var url = $(obj).attr('url');
			var page = $(obj).attr('page');
			var lastpage = $(obj).attr('lastpage');
			var status = $(obj).attr('status');
			
			if (url == "" || url == null || url == "null") return;
			if (lastpage == page || status == "loading") return;
			
			
			var suffix = "?";
			if (url.indexOf("?") > -1) suffix = "&";
			
			clearInterval( self.timer );
			
					
			var callback = function(r,s,x) {
				if (s == "success" && typeof(r) != "undefined") {
						$(obj).unmask();
						$(obj).attr('lastpage',page);
					  $(obj).attr('status','loaded');
					  
					  self.timer = setInterval(function () {
							slide();
						}, self.options.transition_interval);
				}
			};
			
			
			$(obj).css('min-height','60px');
			$(obj).mask('Loading...');
			$(obj).attr('status','loading');
			$(obj).load(url+suffix+"page="+page,'',callback);
					
		}
		
		
		
		

		options.pause_on_hover		= options.pause_on_hover		|| true;
		options.transition_interval	= options.transition_interval	|| 5000;
		
		loadAjaxContent(output.eq(visible_item).get(0));
		output.hide().eq( visible_item ).show();
		tabs.eq( visible_item ).addClass('current');

		tabs.click(function() {
			if ($(this).hasClass('current')) {
				return false;	
			}

			slide( tabs.index( this) );
		});
		
		
		if (options.transition_interval > 0) {
			var timer = setInterval(function () {
				slide();
			}, options.transition_interval);

			if (options.pause_on_hover) {
				tabs.mouseenter(function() {
					clearInterval( timer );

				}).mouseleave(function() {
					clearInterval( timer );
					timer = setInterval(function () {
						slide();
					}, options.transition_interval);
				});
				
				output.mouseenter(function() {
					clearInterval( timer );

				}).mouseleave(function() {
					clearInterval( timer );
					timer = setInterval(function () {
						slide();
					}, options.transition_interval);
				});
				
				
				
			}
		}
		
		
	};

function toggleFlash(disp) {
  
  
  //if ($.browser.msie)  return;
  
	$("object").each(function() {
		//$(this).css("display",disp);
		$(this).css("visibility",disp);
	});

	$("embed").each(function() {
		//$(this).css("display",disp);
		$(this).css("visibility",disp);
	});
}


var g_flash_semaphore= 0 ;
function showFlash() {	g_flash_semaphore--;	if (g_flash_semaphore == 0) 		toggleFlash('visible');}
function hideFlash() {	g_flash_semaphore++;	toggleFlash('hidden');}

var ovMessageBox = function(tit,msg,callback) {
	 
	var c = function() {
		showFlash();
		if (callback != null && typeof(callback) != "undefined") {
			callback();
		}

	};

	Boxy.alert(msg+"<br><br>",null,{
				afterHide : c,
				afterShow : hideFlash,
				title : tit
		}
	);
	
}.defaults('','',null);

var ovConfirm = function(tit , message , callback ) {

	question = message;
	answers = [STR_YES,STR_NO];
	var icallback = function(str) {
		if (str == STR_YES)
			callback("yes");
		else
			callback("no");
	}
	
	Boxy.ask(question, answers, icallback , {
			title : tit	,
			afterHide : showFlash,
			afterShow : hideFlash
	});

};

var ovAlert = function(str , title) {
	if (title.trim() != "") {
		if (str != "") title += " : ";
		$("#alert_container_title").html(title);
		$("#alert_container_msg").html(str);
	}else {
		$("#alert_container_title").html(str);
		$("#alert_container_msg").html("");
	}
	
	var folder = $("#alert_container");
	
	if ($.browser.msie) {
		$.browser.msie8 = $.browser.msie && /MSIE 8.0/i.test(window.navigator.userAgent) && !/MSIE 7.0/i.test(window.navigator.userAgent);
		if (!$.browser.msie8) {
			var _st = document.documentElement.scrollTop > document.body.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ;
			var _sl= document.documentElement.scrollLeft > document.body.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ;
			folder.css("left","0px");
			folder.css("top",_st+"px");
		}
	}
	
	folder.slideDown(500);
	
	setTimeout(function()
	{
		ovAlertHide();
	}, 5000);
	
	
	
}.defaults('');

var ovLoadingDlg = null;
var ovOnLoading = function(tit,content,canclose) {
	  ovOffLoading();
	  $(document.body).mask();
	 	ovLoadingDlg = new Boxy('<div class="ov-loading"><b class="title">'+tit+'</b> <br />'+content+'</div>',
	     { closeable: canclose,modal : true, 			afterHide : showFlash,	afterShow : hideFlash}
	  );
	 
}.defaults('Loading... Please wait','<img class="loader" src="/css/images/circle_loading.gif" />',false);

var ovOffLoading = function() {
	if (ovLoadingDlg != null) {
		$(document.body).unmask();
		ovLoadingDlg.hide();
		ovLoadingDlg = null;
	}
};



var ovDivDialog = function(ctitle , html , callback , cmodal ) {
	var cb = function() { if (typeof callback == "function") callback();};
	var options = { center : true, closeable: true , modal : cmodal , 	afterHide : showFlash,	afterShow : cb , title : ctitle};
	new Boxy(html, options);
};
        
var ovDialog = function(ctitle , url , callback , cmodal , _cache) {
	
	var boxyObj = null;
	var cb = function() { if (typeof callback == "function") callback();};
	
	var options = { center : true, closeable: true , cache : _cache , modal : cmodal , 	afterHide : showFlash,	afterShow : cb , title : ctitle};
	
	var movetocenter = function() {
		var s = boxyObj.getSize();
		if (s[0] < 100 && s[1] < 100) {
			setTimeout(function() {
           movetocenter();
      },500);
		}else {
			boxyObj.center();
		}
	};
	
	var ajax = {
        url: url, type: 'GET', dataType: 'html', cache: false, success: function(html) {
            html = $(html);
            if (options.filter) html = $(options.filter, html);
            if (options.center) {
            	
            }
            boxyObj = new Boxy(html, options);
            
            
            setTimeout(function() {
            	movetocenter();
            },300);
            
        }
 };
    
 $.each(['type', 'cache'], function() {
    if (this in options) {
         ajax[this] = options[this];
         delete options[this];
     }
 });
    
 $.ajax(ajax);

}.defaults(null,false,false);

function ovAlertHide() {
	$("#alert_container").slideUp(500);
}

var LOADING_SWITCH = false;

function onLoading() {
	
	var folder = $("#loading_container");
	
	if ($.browser.msie) {
		$.browser.msie8 = $.browser.msie && /MSIE 8.0/i.test(window.navigator.userAgent) && !/MSIE 7.0/i.test(window.navigator.userAgent);
		if (!$.browser.msie8) {
			var _st = document.documentElement.scrollTop > document.body.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ;
			var _sl= document.documentElement.scrollLeft > document.body.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ;
			folder.css("left","0px");
			folder.css("top",_st+"px");
		}
	}
	
	LOADING_SWITCH = true;
	setTimeout(function()
	{
		if (LOADING_SWITCH) $("#loading_container").show();
	}, 2000);

	

}

function offLoading() {
	LOADING_SWITCH = false;
	ovOffLoading();
	$("#loading_container").hide();
	$(".loadmask-msg,.loadmask").remove();
	$(".masked").removeClass("masked");
	$(".masked-relative").removeClass("masked-relative");
	$(".masked-hidden").removeClass("masked-hidden");
}

function autogrow (e) {
	  if (this.clientHeight < this.scrollHeight) { $(this).css("height",(this.scrollHeight+10)+"px");	}
}

var setAutogrow = function() {
	$('textarea.resizable:not(.processed)').TextAreaResizer();
	$("textarea.expandable").live("keyup",autogrow);
};


function toggleDownDisplay(id , obj) {
	
	toggleDisplay(id);
	if ($("#"+id).css("display") == "none") 
		$(obj).find("a").removeClass("up").removeClass("down").addClass("down");
	else
		$(obj).find("a").removeClass("up").removeClass("down").addClass("up");
		
}

function toggleDisplay(id) {
	
	var id = "#"+id;
	if ($(id).css("display") == "none") {
		$(id).show();
	}else
		$(id).hide();

}

function changeBgColor(obj , c) {
	$(obj).css('background-color',c);

//	obj.style.background = c;
}



/**************************************
 * General Functions
 **************************************/

//form default value check

function inputOnClick(val , ele ) {
	
	$(ele).attr('defaultvalue',val);
	if (ele.value.trim() == val) {
			ele.value = '';
	}
}
function inputOnBlur(ele) {
	if (ele.value.trim() == "") {
			ele.value = $(ele).attr('defaultvalue');
	}
}

//embed
function embedSelect(obj){
	
	obj.focus();
	obj.select();
}

//overlay ads
function turnOffOverlay(ov_id) {
	//if (!checkLogin()) return false;
	
	var callback = function(str) {
		$('#'+ov_id).fadeOut(500);	
	};
	
	get('/action/session.overlay.php?ov_id='+ov_id+'&onoff=off',callback,true);
}

//scroll content


var jumpContent = function(id , page , effect) {
	
	var maxc = parseInt($(id).attr('max'));
	var group = $(id).attr('group');
	var cid = parseInt($(id).attr('cid'));
	if (cid == "") cid = 0;
	cid = parseInt(page);
	
	if (effect == '')
	{
		$("."+group).hide();
		$(id+"_"+cid).show();
	}else if (effect == 'fade')
	{
		$("."+group).fadeOut(300);
		$(id+"_"+cid).fadeIn(500);
	}
	
	$(id).attr('cid',cid);
	
}.defaults('');

var scrollContent = function(id , gap , effect) {
	
	var maxc = parseInt($(id).attr('max'));
	var group = $(id).attr('group');
	var cid = parseInt($(id).attr('cid'));
	if (cid == "") cid = 0;
	cid += parseInt(gap);
	if (cid < 0) cid = maxc-1;
	cid %= maxc;
	if (effect == '')
	{
		$("."+group).hide();
		$(id+"_"+cid).show();
	}else if (effect == 'fade')
	{
		$("."+group).fadeOut(300);
		$(id+"_"+cid).fadeIn(500);
	}
	
	$(id).attr('cid',cid);
	
}.defaults('');

//languages
var languageDialog = function() {
	
	var disp = $("#language_box").css("display");
	if (disp != "none") {
		$("#language_box").fadeOut(300);
		return;
	}

	var pos = $("#global").offset();
	var left = parseInt(pos.left);
	left += $("#global").width() + 20;
	left -= $("#language_box").width();
	
	var top = parseInt(pos.top) + 18;
	$("#language_box").css("left",left+"px");
	$("#language_box").css("top",top+"px");
	$("#language_box").fadeIn(300);
	
		
}.defaults();


function changeMature(obj) {
	var mature = $(obj).attr('mature');
	var nmature = "";
	if (mature == null || typeof(mature) == "undefined" || mature=="null" || mature == "") {
		mature = "no";
	}
	if (mature == "no") nmature = "yes";
	else nmature = "no";
	
	var callback = function(str) {
		ovAlert(str);
		$(obj).attr('mature',nmature);
		$(obj).text($(obj).attr(nmature+'_text'));
		location.reload();
	};
	get('/action/session.mature.php?mature='+nmature,callback);
}

function changeLanguage(lang) {
	var orgurl = location.href;
	if (orgurl.indexOf("#") > 0) {
		orgurl = orgurl.substring(0,orgurl.indexOf("#"));
	}
	
	if (orgurl.indexOf("?") > 0) {
		orgurl += "&language="+lang;
	}else
		orgurl += "?language="+lang;
	go(orgurl);
	
}

//admin menu

function adminMenuOpen() {
	$("#admin_div").fadeIn(1000);
	anchor("admin_div");
}

//user dialog
var usermenuDialog = function() {
	
	var disp = $("#usermenu_box").css("display");
	if (disp != "none") {
		$("#usermenu_box").fadeOut(300);
		return;
	}

	var pos = $("#usermenu").offset();
	var left = parseInt(pos.left);
	//left += $("#usermenu").width();
	//left -= $("#usermenu_box").width();
	
	var top = parseInt(pos.top) + 18;
	$("#usermenu_box").css("left",left+"px");
	$("#usermenu_box").css("top",top+"px");
	$("#usermenu_box").fadeIn(300);
	
		
}.defaults();

//searches
function searchContent(iv) {
	var f = document.search_form;
	if (f.q.value==iv) {
		return false;
	}
	f.submit();	
}


function setSearchOption(val,ele) {
	$("#search_menu").children("li").removeClass("selected");
	$("#search_menu").children("li").children("a").css("font-weight","normal");
	$li = $(ele).parent("li");
	$li.addClass("selected");
	$(ele).css("font-weight","bold");
	var f = document.search_form;
	f.cate.value = val;
	
}

//artwork actions
function showContext(div) {
	$(div).find(".aichw").show(0);
	//$(div).find(".aicth,.aicnh,.aicc,.aics").show(0);
	/*
	var offset = $(div).offset();
	var desc = $(div).find(".artwork-desc");
	$(desc).css("left",offset.left+"px");
	$(desc).css("top",offset.top+"px");
	$(desc).css("visibility","visible");
	$(div).css("background","#fff");
	*/
}

function hideContext(div) {
	$(div).find(".aichw").hide(0);
	//$(div).find(".aicth,.aicnh,.aicc,.aics").hide(0);
	/*
	$(div).find(".artwork-desc").css("visibility","hidden");
	$(div).css("background","#f9f9f9");
	*/
}



var showDropdown = function(ele) {
		
		var ul = $(ele).children("ul");
		var fl = parseFloat($.browser.version);

		//if($.browser.msie && fl <= 6.0) {
		//alert($.data(ele,'ul_id'));
		
		if ($.data(ele,'ul_id') == null || $.data(ele,'ul_id') == "null") {
			var off = $(ele).offset();
			var h = $(ele).height() + parseInt($(ele).css("padding-top")) + parseInt($(ele).css("padding-bottom"));
			var ul_copy = $(ul).clone();
			$(ul).remove();
			ul = ul_copy;
			$(ul).appendTo('body');
			var id = seed(10);
			$(ul).attr('id',id);
			$.data(ele,'ul_id',id);
			$(ul).css('position','absolute');
			$(ul).css('left',off.left+"px");
			$(ul).css('top',(off.top+h) +"px");
		}else {
			ul = $('#'+$.data(ele,'ul_id'));
		}
		
		//}
		
		if ($(ul).attr("activate") == "true") {
			/*
			$(ul).attr("activate","false");
			$(ul).hide();
			*/
			
		}else {
			
			$(ul).attr("activate","true");
			$(ul).show();
			$(ul).hover(
				function(e) {
			
					if ($(ul).attr("activate") == "true")	$(ul).show();
					else {
						$(ul).hide();
						$(ul).unbind('mouseover mouseout hover mouseenter mouseleave');
					}
					e.stopPropagation();
						
				},
				function(e) {
					$(ul).attr("activate","false");
				  $(ul).hide();
				  $(ul).unbind('mouseover mouseout hover mouseenter mouseleave');
				  e.stopPropagation();
				}
			);
			
		}
		
		
		$(ul).find("a.close").click(function(e) {
			$(ul).unbind('mouseover mouseout hover mouseenter mouseleave');
			$(ul).attr("activate","false");
			$(ul).hide();
			e.stopPropagation();
		});
		
		
		//$(document).not("ul").click(func);
		//$(ul).css("visibility","visible");
};



function hideDropdown(ele) {
		
		var ul = $(ele).children("ul");
		if ($.data(ele,'ul_id') != null && $.data(ele,'ul_id') != "null") { ul = $.data(ele,'ul_id');}
		$(ul).attr("activate","false");
		$(ul).unbind('mouseover mouseout hover mouseenter mouseleave');
		$(ul).hide();

}

var goLogin = function(answer) {

	if (answer != 'yes') return;

	$a = $('#sign_in > a');
	var href = $a.attr('href');
	if (typeof(href) != "undefined" && href != null)
	{
		go(href);
	}else 
		go('/login/');
}.defaults('yes');


function addFan(no) {
	if (!checkLogin()) return;
	
	var q = "?no="+no;
	var url = "/action/add.fan.php";
	var data = queryParse(q);
	var fid = seed(10);
	var cf = createForm(fid,data,url,'POST');

	
	var callback = function(str) {
		ovAlert(str);
		$('#add_fav_button').hide();
	};

	post(url,fid,callback);
	
}


/*******************************************
 * Initialization
 *******************************************/

(function(){
    /*Use Object Detection to detect IE6*/
    var m = document.uniqueID /*IE*/
    && document.compatMode /*>=IE6*/
    && !window.XMLHttpRequest /*<=IE6*/
    && document.execCommand ;

    try{
		 try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}  
		 
    }catch(oh){};
})(); 

$(document).ready(function() {
	$.ajaxSetup({cache:false});
	setAutogrow();
	$.cookie('screenWidth',screen.width);
	$.cookie('screenHeight',screen.height);
	
});


