zD=30
extraPageActive=0
DELAYTIMER_resize=null
isIE=(navigator.userAgent.indexOf("MSIE")!=-1)
isIE6=(navigator.userAgent.indexOf("MSIE 6")!=-1)


$(function() {
	
	RESIZE_H(0)
	
	StateManager = EXANIMO.managers.StateManager;
	StateManager.onstatechange = function(e) {	
		checkSTATE(e)
	}
	RunSTATEactive=0
	LAST_URL=""

	StateManager.initialize()
	RunSTATE()

	$('#dateA').addClass('festivaldateactive')
		
});

function TO_FRONT(n) {
	$('#'+n).css('zIndex',zD)
	zD++
}


function changeDate(id) {
	StateManager.setState('DATE,'+id)	
}



function releaseRunSTATE() {
	// RunSTATE get's called 2 times if the site is accessed directly
	// to prevent 2 times calling it, make a small timeout
	RunSTATEactive=0
}

function RunSTATE() {
	// executes everything that is necessary to interpret the URL and shows the right content
	
	if (RunSTATEactive==1) {
		return
	}
	RunSTATEactive=1
	setTimeout("releaseRunSTATE()", 500) // block this function for 500ms
	
	var TEMP=new Array()
	TEMP=splitURL()
	
	if (TEMP.join(',')==LAST_URL) {
		// same URL again, don't do anything
		return
	}
	LAST_URL=TEMP.join(',')
	
	
	if (TEMP[0]=="ARTISTS") {
		showExtrapage('EP_1')
		
	} else if (TEMP[0]=="TICKETS") {
		
		showExtrapage('EP_2')
		
	} else if (TEMP[0]=="PARTNERS") {

		showExtrapage('EP_3')
		
	} else if (TEMP[0]=="PAGE") {
		
		showExtrapage('PAGE_'+TEMP[1])
		
		
	} else {
		
		hideExtrapage()
	
		if (TEMP[0]=="DATE") {
			$('.festivaldateactive').removeClass('festivaldateactive').addClass('festivaldate')
			$('#date'+TEMP[1]).addClass('festivaldateactive')
		
			$('#PROGRAM_CONTENT').load('_INCL/loaddate.php?id='+TEMP[1], function() { resizeScrollers() } )
			
		}
		
	}
			
	
}

function closeExtraPage() {
	StateManager.setState(',')
	
}


function openSubpage(id) {
	StateManager.setState('PAGE,'+id)
}

function showExtrapage(id) {
	extraPageActive=1
	TO_FRONT('EXTRAPAGE')
	RESIZE_H(1)
	$('#extrapage_title').html('')
	$('#EX_CONTENT').html('')
	$('#extrapage_title').load('_INCL/loadtitle.php?id='+id)
	$('#EX_CONTENT').load('_INCL/loadExtraPage.php?id='+id, function() { TO_FRONT('EXTRAPAGE'); resizeScrollers() })
	
}

function hideExtrapage() {
	extraPageActive=0
	RESIZE_H(1)
}


function SHOW_PAGES() {
	
	RESIZE_NOW()
	
	$('#BLOG').css({'visibility':'visible', 'display':'none'})
	//$('#NYMUSIKK').css({'visibility':'visible', 'display':'none'})
	
	$('#NEWS').css({'visibility':'visible', 'display':'none'})
	$('#NEWS').fadeIn('slow')
	$('#PROGRAM').css({'visibility':'visible', 'display':'none'})
	$('#PROGRAM').fadeIn('slow', function() { setTimeout("SHOW_REST()", 200) })
	$('#EXTRAPAGE').css({'visibility':'visible', 'display':'block', 'opacity':0})
	
	var h=$(window).height()
	var w=$(window).width()
	
	var vspace=Math.max(0,  (w-970))
	var l=Math.round(vspace/2)
	
	// position BLOG and NYMUSIKK
	BLOG_X=Math.random()*(l-100)
	BLOG_Y=Math.random()*(400)
	$('#BLOG').css({'left':BLOG_X+'px', 'top':BLOG_Y+'px'})
	
	NYMUSIKK_X=Math.random()*(w-300)
	NYMUSIKK_Y=Math.random()*(h-200)
	$('#NYMUSIKK').css({'left':NYMUSIKK_X+'px', 'top':NYMUSIKK_Y+'px'})
		
	$('#BLOG')
	
		.bind( "mousedown", function( event ){
				var temp=$( this ).offset()
				BLOG_X=temp.left
				BLOG_Y=temp.top
			 })					 
        .bind('drag',function( event ){
                $( this ).css({
                        top: event.offsetY,
                        left: event.offsetX
                        });
                })
		.bind('mouseup',function( event ){
				var temp=$( this ).offset()
				var bdx=temp.left
				var bdy=temp.top
				var minDist=5
				
				if (Math.abs(bdx-BLOG_X)<minDist && Math.abs(bdy-BLOG_Y)<minDist) {
					popUp('http://happynordicmusicdays.tumblr.com')
				}
        });
		
		
	/*
	$('#NYMUSIKK')
        .bind( "mousedown", function( event ){
				var temp=$( this ).offset()
				BLOG_X=temp.left
				BLOG_Y=temp.top
			 })					 
        .bind('drag',function( event ){
                $( this ).css({
                        top: event.offsetY,
                        left: event.offsetX
                        });
                })
		.bind('mouseup',function( event ){
				var temp=$( this ).offset()
				var bdx=temp.left
				var bdy=temp.top
				var minDist=5
				
				if (Math.abs(bdx-BLOG_X)<minDist && Math.abs(bdy-BLOG_Y)<minDist) {
					popUp('http://nymusikk.no')
				}
        });
		*/
		
}


function popUp(URL) {
	day = new Date()
	id = day.getTime()
	var h=screen.height-200
	var w=screen.width-200
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=" + w + ",height=" + h + ",left=100,top=30');")
}



function SHOW_REST() {
	$('#LOGO').fadeIn('fast')
	$('#NEWSLETTER').fadeIn('fast')
	$('#SPONSORS').fadeIn('fast')
	$('#BLOG').css({'display':'block', 'visibility':'visible', 'opacity':0}).animate({'opacity':1, 'left':'+=50', 'top':'+=10'}, 1000)
	//$('#NYMUSIKK').css({'display':'block', 'visibility':'visible', 'opacity':0}).animate({'opacity':1, 'left':'-=50', 'top':'-=10'}, 1000)
	
}


function RESIZE() {
	clearTimeout(DELAYTIMER_resize)
	DELAYTIMER_resize=setTimeout('RESIZE_NOW()',200)			
}


function RESIZE_NOW() {
	
	clearTimeout(DELAYTIMER_resize)
	var h=$(window).height()
	var w=$(window).width()

	var xoffset=Math.max(0,Math.round((w-726)/2))
	var minH=Math.max(550,h-20)
	var margBottom=22+17
		
	var newsH=minH-270
	$('#NEWS').css({'height':newsH})
	$('#PROGRAM').css({'height':newsH})
	$('#EXTRAPAGE').css({'height':newsH})
	
	
	var nltop=Math.max(h-175, 396)
	$('#NEWSLETTER').css({'top':nltop+'px'})
	
	resizeScrollers()
	
	RESIZE_H(1)
	
}


function resizeScrollers() {
	
	var h=$(window).height()
	var w=$(window).width()

	var xoffset=Math.max(0,Math.round((w-726)/2))
	var minH=Math.max(550,h-20)
	var margBottom=22+17
	var margBottom2=40
	var margBottom3=15
	var newsH=minH-270
	
	$('#NEWS_HOLDER').css('height', newsH-margBottom+'px');
	$('#NEWS_CONTENT').css('height', newsH-margBottom+'px');
	$('#NEWS_HOLDER>.jScrollPaneContainer').css({'height':newsH-margBottom +'px'});
	$('#NEWS_CONTENT').jScrollPane({scrollbarWidth:13, scrollbarMargin:28})
	
	$('#PROGRAM_HOLDER').css('height', newsH-margBottom-margBottom2+'px');
	$('#PROGRAM_CONTENT').css('height', newsH-margBottom-margBottom2+'px');
	$('#PROGRAM_HOLDER>.jScrollPaneContainer').css({'height':newsH-margBottom-margBottom2 +'px'});
	$('#PROGRAM_CONTENT').jScrollPane({scrollbarWidth:13, scrollbarMargin:28})
	
	$('#EX_HOLDER').css('height', newsH-margBottom-margBottom3+'px');
	$('#EX_CONTENT').css('height', newsH-margBottom-margBottom3+'px');
	$('#EX_HOLDER>.jScrollPaneContainer').css({'height':newsH-margBottom-margBottom3 +'px'});
	$('#EX_CONTENT').jScrollPane({scrollbarWidth:13, scrollbarMargin:28})
	
	
	
}

function RESIZE_H(doAnimation) {
	
	// vertical posititioning
	var h=$(window).height()
	var w=$(window).width()
	
	var vspace=Math.max(0,  (w-970))
	var l=Math.round(vspace/2)
	
	var aTime=(doAnimation) ? 700:1
	var ea=(doAnimation) ? 'easeInOutQuad':'linear'
	
	$('#LOGO').animate({'left':l+'px'}, aTime, ea, function() { })
	$('#NEWSLETTER').animate({'left':l+35+'px'}, aTime, ea,  function() { })
	$('#SPONSORS').animate({'left':l+400+'px'}, aTime, ea, function() { })
	
	var xo=100
	var xoo=130
		
	if (extraPageActive==0) {
		
		$('#NEWS').animate({'left':l+352+'px'}, aTime, ea,  function() { })
		$('#PROGRAM').animate({'left':l+352+150+'px'}, aTime, ea,  function() { })
		TO_FRONT('EXTRAPAGE')
		$('#EXTRAPAGE').animate({'opacity':0}, aTime, function() { $('#EXTRAPAGE').css('zIndex',0) } )
		$('#EXTRAPAGE').css({'left':l+352-xo+xoo+xoo+'px'})
	
	} else {
	
		$('#NEWS').animate({'left':l+352-xo+'px'}, aTime, ea,  								function() { })
		$('#PROGRAM').animate({'left':l+352-xo+xoo+'px'}, aTime, ea,  						function() { })
		$('#EXTRAPAGE').animate({'opacity':1.0,'left':l+352-xo+xoo+xoo+'px'}, aTime, ea, 	function() { })
		
	}
	
}

function splitURL() {
	// splits the URL and returns an array with the different elements
	var temp=document.location.href.split("#")
	var tempsecs
	
	if (temp.length>1) {
		if (temp[1]!="") {
			tempsecs=temp[1].split(",")
		} else {
			tempsecs=new Array('','','')
		}
	} else {
		tempsecs=new Array('','','')
	}
	return tempsecs
}

function checkSTATE(e) {
	// checks the URL hash

	SECTIONextraparams=e.id.split(",")
	e.id=SECTIONextraparams[0]
	currentSection=e.id

	RunSTATE()
	
	if (SECTIONextraparams.length>0) {
		
		var title=SECTIONextraparams[0].replace(/_/g, " ")
		if (title=="") {
			title="Startpage"
		}
		StateManager.setTitle('Happy Nordic Music Days / ' + title);
		
	} else {
		StateManager.setTitle('Happy Nordic Music Days');
		
	}
}


function getNewsletter() {

	var re =/^[A-Za-z0-9\.\-\_]*?[A-Za-z0-9\.\-\_]+@[A-Za-z0-9\.\-\_]+[\w.-]*?\.[A-Za-z0-9]{2,5}$/;
	var email=$('#email').val()
	
	if (email.match(re)) {
		var name=$('#field1').val()
		if (name=="<Your name>") {
			$('#field1').val('')
		}
		sendNewsletterVars()
		
	} else {
		$('#email').val('Please use a valid email.')
	}
	
}

function restoreNL() {
	$('#newslettercontent').html(newsletterBACKUP)
}

function sendNewsletterVars() {
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Please use a modern browser, such as the latest Firefox, Safari, Opera or Internet Explorer. Sorry for the inconvenience.");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			
			if (xmlHttp.responseText.indexOf("Subscription request received")!=-1) {
				MailOK()
			} else {
				MailBAD()
			}
		}
	}

	xmlHttp.open("POST","_MAILINGLIST/user/process.php",true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1255");
	var name=$('#field1').val()
	var email=$('#email').val()
	xmlHttp.send('pommo_signup=true&d[1]='+name+'&d[2]=individual&Email='+email);
	
	$('#newslettercontent').html('Sending your request.')
}

function MailOK() {
	
	var a='<span class="storeboldbig">THANKS!</span><br /><br />A confirmation mail has been sent to you.<br />Please follow its instructions to complete your subscription.<br /><br /><a href="javascript:restoreNL()">Subscribe another person</a>'
	
	$('#newslettercontent').html(a)
}

function MailBAD() {
	var a='<span class="storeboldbig">SORRY..</span><br /><br />Probably an error has occured while sending your email address.<br />If you don\'t receive a confirmation mail, please try again. Maybe you\'re already on our list?<br /><a href="javascript:restoreNL()">Try again</a>'
	$('#newslettercontent').html(a)
}

$(document).ready(function() { 
	newsletterBACKUP=$('#newslettercontent').html()
}); 



// --------------------------- --------------------------- --------------------------- ---------------------------
// JQUERY PLUGINS
// --------------------------- --------------------------- --------------------------- ---------------------------

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});


/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-06-20 16:25:35 -0500 (Wed, 20 Jun 2007) $
 * $Rev: 2125 $
 *
 * Version: 2.2
 */
(function($){$.fn.extend({mousewheel:function(f){if(!f.guid)f.guid=$.event.guid++;if(!$.event._mwCache)$.event._mwCache=[];return this.each(function(){if(this._mwHandlers)return this._mwHandlers.push(f);else this._mwHandlers=[];this._mwHandlers.push(f);var s=this;this._mwHandler=function(e){e=$.event.fix(e||window.event);$.extend(e,this._mwCursorPos||{});var delta=0,returnValue=true;if(e.wheelDelta)delta=e.wheelDelta/120;if(e.detail)delta=-e.detail/3;if(window.opera)delta=-e.wheelDelta;for(var i=0;i<s._mwHandlers.length;i++)if(s._mwHandlers[i])if(s._mwHandlers[i].call(s,e,delta)===false){returnValue=false;e.preventDefault();e.stopPropagation();}return returnValue;};if($.browser.mozilla&&!this._mwFixCursorPos){this._mwFixCursorPos=function(e){this._mwCursorPos={pageX:e.pageX,pageY:e.pageY,clientX:e.clientX,clientY:e.clientY};};$(this).bind('mousemove',this._mwFixCursorPos);}if(this.addEventListener)if($.browser.mozilla)this.addEventListener('DOMMouseScroll',this._mwHandler,false);else this.addEventListener('mousewheel',this._mwHandler,false);else
this.onmousewheel=this._mwHandler;$.event._mwCache.push($(this));});},unmousewheel:function(f){return this.each(function(){if(f&&this._mwHandlers){for(var i=0;i<this._mwHandlers.length;i++)if(this._mwHandlers[i]&&this._mwHandlers[i].guid==f.guid)delete this._mwHandlers[i];}else{if($.browser.mozilla&&!this._mwFixCursorPos)$(this).unbind('mousemove',this._mwFixCursorPos);if(this.addEventListener)if($.browser.mozilla)this.removeEventListener('DOMMouseScroll',this._mwHandler,false);else this.removeEventListener('mousewheel',this._mwHandler,false);else
this.onmousewheel=null;this._mwHandlers=this._mwHandler=this._mwFixCursorPos=this._mwCursorPos=null;}});}});$(window).one('unload',function(){var els=$.event._mwCache||[];for(var i=0;i<els.length;i++)els[i].unmousewheel();});})(jQuery);



/* 
jquery.event.drag.js ~ v1.5 ~ Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)  
Liscensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt
*/
(function(E){E.fn.drag=function(L,K,J){if(K){this.bind("dragstart",L)}if(J){this.bind("dragend",J)}return !L?this.trigger("drag"):this.bind("drag",K?K:L)};var A=E.event,B=A.special,F=B.drag={not:":input",distance:0,which:1,dragging:false,setup:function(J){J=E.extend({distance:F.distance,which:F.which,not:F.not},J||{});J.distance=I(J.distance);A.add(this,"mousedown",H,J);if(this.attachEvent){this.attachEvent("ondragstart",D)}},teardown:function(){A.remove(this,"mousedown",H);if(this===F.dragging){F.dragging=F.proxy=false}G(this,true);if(this.detachEvent){this.detachEvent("ondragstart",D)}}};B.dragstart=B.dragend={setup:function(){},teardown:function(){}};function H(L){var K=this,J,M=L.data||{};if(M.elem){K=L.dragTarget=M.elem;L.dragProxy=F.proxy||K;L.cursorOffsetX=M.pageX-M.left;L.cursorOffsetY=M.pageY-M.top;L.offsetX=L.pageX-L.cursorOffsetX;L.offsetY=L.pageY-L.cursorOffsetY}else{if(F.dragging||(M.which>0&&L.which!=M.which)||E(L.target).is(M.not)){return }}switch(L.type){case"mousedown":E.extend(M,E(K).offset(),{elem:K,target:L.target,pageX:L.pageX,pageY:L.pageY});A.add(document,"mousemove mouseup",H,M);G(K,false);F.dragging=null;return false;case !F.dragging&&"mousemove":if(I(L.pageX-M.pageX)+I(L.pageY-M.pageY)<M.distance){break}L.target=M.target;J=C(L,"dragstart",K);if(J!==false){F.dragging=K;F.proxy=L.dragProxy=E(J||K)[0]}case"mousemove":if(F.dragging){J=C(L,"drag",K);if(B.drop){B.drop.allowed=(J!==false);B.drop.handler(L)}if(J!==false){break}L.type="mouseup"}case"mouseup":A.remove(document,"mousemove mouseup",H);if(F.dragging){if(B.drop){B.drop.handler(L)}C(L,"dragend",K)}G(K,true);F.dragging=F.proxy=M.elem=false;break}return true}function C(M,K,L){M.type=K;var J=E.event.handle.call(L,M);return J===false?false:J||M.result}function I(J){return Math.pow(J,2)}function D(){return(F.dragging===false)}function G(K,J){if(!K){return }K.unselectable=J?"off":"on";K.onselectstart=function(){return J};if(K.style){K.style.MozUserSelect=J?"":"none"}}})(jQuery);




