﻿/*
 * jQuery VisDynamica plugin
 * http://visdynamica.com
 * 2011-11-04
 * 
 * Copyright 2011, Tomek Seroczyński, visdynamica@gmail.com
 * All rights reserved. This code can be used only with the generated VisDynamica prototype it was automatically created for.
 * It can not be copied, in whole or in part, in any form or by any means, as is or with alterations, without the written permission of the author.
 * 
 */
top.window.isVisDynamica = true;
top.window.isFieldFocused = false;
if( typeof top.window.mobileContentBox == 'undefined' || top.window.mobileContentBox !== 1 ){ top.window.mobileContentBox = []; };
window.oldOrientation = -1;
top.window.isTouchDevice = false;
try{ document.createEvent( 'TouchEvent' ); top.window.isTouchDevice = true; }catch(e){};
if( top.window.isTouchDevice !== true || typeof window.orientation === 'undefined' ){ window.orientation = ( $(window).width() > $(window).height() ) ? 90 : 0; }

(function( $ ){
	
	var stickedLayoutZIndex = 1000;
	var popupLayoutZIndex = 100000;
	
	var tools = {
		
		hideMobileAddressBar : function(){
			if( window.pageYOffset !== 1 && top.window.isFieldFocused == false ){ window.scrollTo( 0, 1 ); };
			setTimeout( function(){ $.vdTools( 'hideMobileAddressBar' ); }, 500 );
		},
		
		getId : function( o ){
			return o.substring( 0, o.indexOf( ' ' ) );
		},
		
		scrollElement : function( o ){
			var v = (o[0]+',,,').split( ',' );
			if( v.length > 0 ){
				if( v[1] == '' ){ v[1] = '0'; }
				if( v[2] == '' ){ v[2] = '100'; }
				if( v[3] != 'swing' && v[3] != 'linear' ){ v[3] = 'swing'; }
				(o[1]).animate( { scrollLeft: '+=' + parseInt( v[0] ), scrollTop: '+=' + parseInt( v[1] ) }, parseInt( v[2] ), v[3] );
			};
		},
		
		triggerLink : function( o ){
			if( $.isArray( o ) ){
				if( o.length < 2 ){ return false; };
				var i, p = [];
				try{ p = $( o[0].s ).data('d').pL; }catch( e ){};
				if( p.length !== 1 ){ try{ p = $( o[0].s ).parent().closest( '.VD.l' ); }catch( e ){}; };
				for ( i = 0; i < o.length; i++ ){ if( typeof o[i] == 'object' ){ o[i].p = p; $.vdTools( 'triggerLink', o[i] ); }; };
			}
			else{
				var s = { l: '#', a: '', pW: 0, pH: 0, m: '', t: '', s: null, p: [], h: 'Yes', f: '' };
				var ref = $(document);
				if( o ){ $.extend( s, o ); }
				if( s.l == '#' || s.l == '' ){ return false; }
				if( s.a.indexOf( '>' ) > -1 ){ s.a = s.a.replace( ' ', '' ).split( '>' ); s.t = s.a[ 1 ]; s.a = s.a[ 0 ]; }
				if( s.t.indexOf( '*' ) > -1 ){ s.t = s.t.replace( ' ', '' ).split( '*' ); s.f = s.t[ 0 ]; s.t = s.t[ 1 ]; }
				var tL = [];
				if( s.t !=='' ){
					if( s.f !== '' ){ ref = $('iframe.'+s.f).contents(); }
					tL = ref.find('.'+s.t+'.VD.l.VDRegisteredLB,.'+s.t+'.VD.d.VDRegisteredDL');
					if( tL.length < 1 ){
						if( ref.find('.'+s.t+'.VD.l,.'+s.t+'.VD.d').length > 0 ){ setTimeout( function(){ $.vdTools( 'triggerLink', o ) }, 100 ); return false; }
						else{ alert("PROTOTYPE ERROR: There is a link pointing to a missing Layout box: '"+s.t+"'."); return false; }
					};
				};
				if( s.l == 'GoBack' ){ s.m = 'Back'; }
				else if( s.l == 'DoScroll' ){
					if( s.t !== '' && tL.length > 0 ){ 
						if( s.f !== '' ){ window.frames[ s.f ].t( tL, 'vdScrollElement', [ s.a ] ); }
						else{ tL.trigger( 'vdScrollElement', [ s.a ] ); }
					}
					else if( s.m == 'Top' || s.f == 'Top' || $(s.s).parent().closest('.VD.l').length === 0 ){ $(window).trigger( 'vdScrollElement', [ s.a ] ); }
					else{ try{ $(s.s).parent().closest('.VD.l').trigger( 'vdScrollElement', [ s.a ] ); }catch( e ){}; }
					return false;
				}
				else if( s.l == 'DoClose' ){
					if( s.t !== '' && tL.length > 0 ){ 
						if( s.f !== '' ){ window.frames[ s.f ].t( tL, 'vdHideElement', false ); }
						else{ tL.trigger( 'vdHideElement' ); }
					}
					else{ try{ $(s.s).parent().closest('.VD.l').trigger('vdHideElement'); }catch( e ){}; }
					return false;
				};
				if( s.m == '' || typeof s.m === 'undefined' ){ s.m = 'Standard'; }
				if( s.l.indexOf( 'mailto:' ) == 0 || s.l.indexOf( 'tel:' ) == 0 ){ s.m = 'Top'; }
				if( s.p.length != 1 ){
					try{ s.p = $( s.s ).data('d').pL; }catch( e ){};
					if( s.p.length !== 1 ){ try{ s.p = $( s.s ).parent().closest( '.VD.l' ); }catch( e ){}; }
				};
				switch( s.m ){
					case 'Standard':
						if( s.t == '' && s.p.length == 1 ){ s.p.trigger( 'vdLoadContent', [ { l: s.l, a: s.a, pW: s.pW, pH: s.pH, h: s.h } ] ); }
						else if( s.t != '' ){ 
							if( s.f !== '' ){ window.frames[ s.f ].t( tL, 'vdLoadContent', [ { l: s.l, a: s.a, pW: s.pW, pH: s.pH, h: s.h } ] ); }
							else{ tL.trigger( 'vdLoadContent', [ { l: s.l, a: s.a, pW: s.pW, pH: s.pH, h: s.h } ] ); }
						}
						else{ window.location.href = s.l+((s.a!='')?'#'+s.a:''); }
						break;
					case 'Back':
						if( s.t == '' && s.p.length == 1 ){ s.p.trigger( 'vdGoBack' ); }
						else if( s.t != '' ){ 
							if( s.f !== '' ){ window.frames[ s.f ].t( tL, 'vdGoBack', false ); }
							else{ tL.trigger( 'vdGoBack' ); }
						}
						break;
					case 'Top':
						window.location.href = s.l+((s.a!='')?'#'+s.a:'');
						break;
					case 'New':
						window.open( s.l+((s.a!='')?'#'+s.a:'') );
						break;
				};
			};
			return false;
		},
		
		registerOrientationSwitch : function( o ){
			var s = { m: 'Portrait', i: '', c: '' };
			if( o ){ $.extend( s, o ); };
			$.data( window, 'd', 
				{
					orF: function( e ){
						if( top.window.mobileContentBox.width() !== $(window).width() ){ top.window.mobileContentBox.css( 'width', $(window).width() ); top.window.mobileContentBox.parent().parent().css( 'width', $(window).width() ); };
						if( ( s.m == 'Landscape' && Math.abs( window.orientation ) == 90 ) || ( s.m == 'Portrait' && window.orientation == 0 ) ){ $.data( window, 'd' ).orA.hide(); }
						else{ $.data( window, 'd' ).orA.show(); };
					},
					orC: function(){
						if( $.data( window, 'd' ).orP !== top.window.mobileContentBox.data('d').current ){
							if( typeof $.data( window, 'd' ).orA !== 'undefined' ){ $.data( window, 'd' ).orA.remove(); }
							top.window.mobileContentBox.unbind( 'vdWindowRotate', $.data( window, 'd' ).orF );
							top.window.mobileContentBox.unbind( 'vdOnChanging', $.data( window, 'd' ).orC );
							delete $.data( window, 'd' ).orA;
							delete $.data( window, 'd' ).orF;
							delete $.data( window, 'd' ).orC;
						};
					},
					orP: top.window.mobileContentBox.data('d').current,
					orA: $( '<div class="VDAlert" style="display:none"><div style="' + s.c + '">' + ( ( s.i == '' ) ? '' : '<p>' + s.i + '</p>' ) + '<img src="../img/rotate' + s.m + '.png" /></div></div>' ).appendTo( 'body' )
				}
			);
			top.window.mobileContentBox
				.addClass( 'fireAtRotate' )
				.bind( 'vdWindowRotate', $.data( window, 'd' ).orF )
				.bind( 'vdOnChanging', $.data( window, 'd' ).orC );
			$.data( window, 'd' ).orF.apply( window, [ 0 ] );
			return false;
		}
		
	}

	$.vdTools = function( tool ){
		if( tools[ tool ] ){ return tools[ tool ].apply( this, Array.prototype.slice.call( arguments, 1 )); }
		else{ $.error( 'Tool ' +  tool + ' does not exist on jQuery.vdTools' ); }
	};

	
	var methods = {

		hasEvent : function( o ){
			var e = this.data( 'events' ); return( e && e[ o ] );
		},
		
		postponeAction : function( n, f ){
			if( typeof this.data('d') != 'undefined' ){
				if( typeof this.data('d').queue[ n ] == 'number' ){ clearTimeout( this.data('d').queue[ n ] ); };
				this.data('d').queue[ n ] = setTimeout( f, 500 );
			};
		},

		isVisible : function(){
			var th = this.eq( 0 );
			var ps = th.parents( '.VD.l' );
			if( ps.length < 1 ){ return true; }
			var p = { size: { width: 0, height: 0 }, position: { top: 0, left: 0 } };
			var i = 0;
			var inX, inY = false;
			var d = {};
			for ( i = 0; i < ps.length; i++ ){
				p = { scrollbars: { x: ( ps.eq( i ).css( 'overflow-x' ) == 'auto' ), y: ( ps.eq( i ).css( 'overflow-y' ) == 'auto' ) }, size: { width: ps.eq( i ).width(), height: ps.eq( i ).height() }, position: { top: ps.eq( i ).offset().top, left: ps.eq( i ).offset().left } };
				p.realSize = { width: p.size.width, height: p.size.height };
				try{ d = ps.eq( i ).data('d'); p.scrollbars = { x: d.scrollbars.x, y: d.scrollbars.y }; p.size = { width: d.size.width, height: d.size.height }; }catch( e ){};
				if( p.scrollbars.x && ps.get( i ).scrollWidth > p.realSize.width ){ p.size.width = ps.get( i ).scrollWidth; }
				if( p.scrollbars.y && ps.get( i ).scrollHeight > p.realSize.height ){ p.size.height = ps.get( i ).scrollHeight; }
				if( ( p.position.left + p.size.width < th.offset().left ) || ( p.position.left > th.offset().left + th.width() ) ){ inX = false; }else{ inX = true; };
				if( ( p.position.top + p.size.height < th.offset().top ) || ( p.position.top > th.offset().top + th.height() ) ){ inY = false; }else{ inY = true; };
				if( inX == false || inY == false ){ return false; }
				else if( inX && inY ){ return true; }
			};
			return true;
		},
		
		stickPosition : function( o ){
			var s = { m: '' };
			if( o ){ $.extend( s, o ); }
			if( ( this.length < 1 ) || ( s.m  != 'To top' && s.m  != 'To bottom' && s.m  != "Don't cross the top border" ) ){ return this; }
			this.each( function(){
				var th = $( this );
				var pa = parseInt( th.css( 'padding-top' ) ) + parseInt( th.css( 'padding-bottom' ) );
				if( th.vdCore( 'isVisible' ) ){
					var d = th.data('d');
					if( d.pL.length == 1 ){
						d.pL.trigger( 'vdRegisterOrphans', [ '#' + th.prop( 'id' ) ] );
						th.css( 'marginLeft', th.parent().closest( '.VDPage' ).css( 'marginLeft' ) );
						th.appendTo( $( 'body > .VDPage > .VDCanvas' ) ).css({ 'top': d.position.top + 'px' });
						if ( s.m == "Don't cross the top border" ){
							th.bind( 'vdWindowEvent', function( e, t ){
								if( t >= d.position.top ){ th.removeClass( 'moveWith' + d.pL.prop( 'id' ) ); }
								else{ th.addClass( 'moveWith' + d.pL.prop( 'id' ) ); };
							}).addClass( 'moveWith' + d.pL.prop( 'id' ) );
						};
					};
					if( s.m  == 'To top' ){
						th.css( { top: '0px', zIndex: stickedLayoutZIndex, position: 'fixed', marginLeft: '+=' + parseInt( th.css('left') ) + 'px', left: 'auto' });
					}
					else if( s.m == 'To bottom' ){
						th.css( { top: 'auto', bottom: '0px', zIndex: stickedLayoutZIndex, position: 'fixed', marginLeft: '+=' + parseInt( th.css('left') ) + 'px', left: 'auto' });
					}
					else if( s.m == "Don't cross the top border" ){
						th.bind( 'vdWindowEvent', function( e, t ){
							if( t >= d.position.top ){ th.css( { top: t + 'px' } ); }
							else{ th.css( { top: d.position.top + 'px' } ); };
						})
						.bind( 'vdOnChanged', function( e ){
							if( window.pageYOffset >= d.position.top ){ th.css( { top: window.pageYOffset + 'px' } ); }
							else{ th.css( { top: d.position.top + 'px' } ); };
						})
						.addClass( 'fireAtScroll fireAtResize' );
					};
				};
			});
			return this;
		},
		
		registerLink : function( o ){
			if( ( this.length < 1 ) || ( ! $.isFunction( o ) ) ){ return this; }
			this.each( function(){
				var th = $( this );
				if( ! th.hasClass( 'VDRegisteredL' ) ){
					if( ! th.prop( 'id' ) ){ th.prop( 'id', $.vdTools( 'getId', th.attr( 'class' ) ) + '_' + (+new Date) ); }
					th.data('d',{ pL: th.parent().closest( '.VD.l' ) }).addClass( 'VDRegisteredL' );
				};
				th.bind( 'click', o );
			});
			return this;
		},
		
		registerDynamicLoad : function( o ){
			var st = ( (+new Date) );
			if( ( this.length < 1 ) ){ return this; }
			var s = { i: '', s: 'Mouseover', h: 'Mouseout', d: '0', b: 'Both', cX: 0, cY: 0, pW: 0, pH: 0, l: '#', a: '', pP: 'Top left corner' };
			if( o ){ $.extend( s, o ); }
			s.d = parseInt( s.d );
			// backward compatibility -remove 10.2011
				s.s = s.s.charAt(0).toUpperCase() + s.s.substring(1);
				s.h = s.h.charAt(0).toUpperCase() + s.h.substring(1);
				s.b = s.b.charAt(0).toUpperCase() + s.b.substring(1);
			//-end
			this.each( function(){
				var th = $( this );
				if( th.vdCore( 'isVisible' ) ){
					var id = $.vdTools( 'getId', th.attr( 'class' ) );
					if( ! th.hasClass( 'VDRegisteredDL' ) ){
						if( ! th.prop( 'id' ) ){ th.prop( 'id', id + '_' + (+new Date) ); }
						th.data('d',{
							pL: th.parent().closest( '.VD.l' ),
							zIndex: th.css( 'z-index' ),
							position: { top: th.css( 'top' ), left: th.css( 'left' ) },
							parent: th.parent(),
							previous: th.prev(),
							queue: ''
						}).addClass( 'VDRegisteredDL' );
						if( th.data('d').pL.length == 1 ){
							th.data('d').zIndex = Math.max( parseInt( th.data('d').pL.css( 'z-index' ) ) + 1, parseInt( th.data('d').zIndex ) );
							th.css( 'z-index', th.data('d').zIndex );
							th.data('d').pL.trigger( 'vdRegisterOrphans', [ '#'+ th.prop( 'id' ) ] );
						};
						if( ! th.hasClass( 't' ) ){ th.addClass( 't' ); }
					};
					var d = th.data('d');
					if( $( '.l' + s.i + '_' + id ).length > 0 ){ var thL = $( '.l' + s.i + '_' + id ).eq( 0 );	}
					else{
						var thL = $( '<div id="l' + s.i + '_' + th.prop( 'id' ) + '" class="l' + s.i + '_' + id + ' VD l h d l_' + id + '" style="cursor:default;overflow:hidden;width:' + s.pW + 'px;height:' + s.pH + 'px;z-index:' + d.zIndex + ';"></div>' );
						thL.bind( 'vdOnChanged', function( e ){
							var h = 0; 
							if( s.pP == 'Bottom left corner' ){ try{ h = -1 * thL.data('d').size.height }catch( e ){}; };
							thL.css( 'margin', ( s.cY - parseInt( th.css( 'top' ) ) + h ) + 'px 0 0 ' + ( s.cX - parseInt( th.css( 'left' ) ) ) + 'px' );
						});
						thL.appendTo( 'body > .VDPage > .VDCanvas' ).vdCore( 'registerLayoutBox', { o: 'Resize to content', l: s.l, pW: s.pW, pH: s.pH, a: s.a } );
						if( s.h == 'Mouseout' ){ thL.bind( 'vdLostFocus', function( e ){ $( '.' + id ).trigger( 'vdHideElement', [ thL.prop( 'id' ) ] ); } ); };
					};
					if( d.pL.length == 1 ){ th.parents( '.VD.l' ).trigger( 'vdRegisterScroll', [ '#' + thL.prop( 'id' ) ] ); };
					if( s.h != 'Never' ){ $(window).scroll( function( e ){ thL.trigger( 'vdHideElement' ); } ); };
					th.bind( 'vdShowElement', function( e, t ){
						if( thL.is( ':visible' ) || t !== thL.prop('id') ){ return false; }
						if( e.target.id == th.prop( 'id' ) ){ thL.css( { top: th.offset().top + 'px', left: th.offset().left - $('body > .VDPage > .VDCanvas').offset().left + 'px' } ); };
						if( s.b == 'Just trigger' ){ th.css( { top: th.offset().top + 'px', left: th.offset().left - $('body > .VDPage > .VDCanvas').offset().left + 'px' } ).insertAfter( thL ); };
						if( s.h != 'Never' ){ thL.bind( 'vdOnScroll' , function( e ){ th.trigger( 'vdHideElement' ); } ); }
						thL.trigger( 'vdShowElement' );
						return false;
					});		
					th.bind( 'vdHideElement', function( e, t, n, c ){
						if( typeof c === 'undefined' ){ c = true; }
						if( c ){ th.trigger( 'vdClearDelay' ); }
						if( thL.is( ':hidden' ) || ( t !== thL.prop( 'id' ) && typeof t !== 'undefined' ) ){ return false; }
						if( typeof n === 'undefined' ){ n = ''; }
						if( n == 'SELECT' || n == 'TEXTAREA' || n == 'INPUT' ){ return false; }
						if( typeof t === 'undefined' ){ $( '.l_' + id + '.VD.l' ).unbind( 'vdOnScroll' ).trigger( 'vdHideElement' ); }
						else{ thL.unbind( 'vdOnScroll' ).trigger( 'vdHideElement' ); }
						if( s.b == 'Just trigger' ){
							th.css( { top: d.position.top, left: d.position.left } );
							if( d.previous.length == 1 ){
								if( d.previous.eq( 0 ).next().hasClass( 'VDMrk' ) ){ th.insertAfter( d.previous.eq( 0 ).next() ); }
								else{ th.insertAfter( d.previous.eq( 0 ) ); }
								}
							else{ th.appendTo( d.parent.eq(0) ); }
						};
						return false;
					});
					th.bind( 'vdLoadContent', function( e, c ){
						if( typeof c.s === 'undefined' ){ c.s = 100; }
						thL.trigger( 'vdLoadContent', [ c ] );
						return false;
					});
					th.bind( 'vdRemove', function(){
						th.remove();
						if( $( '.' + id + '.VDRegisteredDL' ).length < 1 ){ $( '.l_' + id).trigger( 'vdRemove' ); }
					});
					if( s.d > 0 ){
						th.bind( 'vdSetDelay', function(){
							if( thL.is( ':visible' ) ){ return false; }
							var eid = '_'+(+new Date); d.queue += '|event' + eid;
							if( s.s == 'Mouseover' ){ th.bind( 'mouseleave', function(){ d.queue = d.queue.replace( '|event' + eid, '' ); } ); };
							setTimeout( function(){ if( ( typeof d !== 'undefined' ) && ( d.queue.indexOf( 'event' + eid ) > 0 ) ){ th.trigger( 'vdShowElement', [ thL.prop('id') ] ); }; }, s.d * 100 );
						});
						th.bind( 'vdClearDelay', function(){ d.queue = ''; } );
					};
					if( ( s.s == 'Click' ) && ( s.h == 'Click' ) ){
						$( '#' + th.prop( 'id' ) + ( ( s.b == 'Just trigger' )? '' : ',#' + thL.prop( 'id' ) ) ).click( function( e ){
							if( thL.is( ':visible' ) ){ th.trigger( 'vdHideElement' , [ thL.prop( 'id' ), e.target.nodeName ] ); }
							else{
								if( s.d > 0 ){ th.trigger( 'vdSetDelay' ); }else{ th.trigger( 'vdShowElement', [ thL.prop( 'id' ) ]);}
							};
						});
					}
					else if( ( s.s == 'Mouseover' ) && ( s.h == 'Click' ) ){
						$( '#' + th.prop( 'id' ) + ( ( s.b == 'Just trigger' )? '' : ',#' + thL.prop( 'id' ) ) )
							.mouseenter( function( e ){ if( s.d > 0 ){ th.trigger( 'vdSetDelay' ); }else{ th.trigger( 'vdShowElement', [ thL.prop( 'id' ) ] ); }; })
							.click( function( e ){ th.trigger( 'vdHideElement', [ thL.prop( 'id' ), e.target.nodeName ] ); });
					}
					else if( ( s.s == 'Mouseover' ) && ( s.h == 'Mouseout' ) ){
						$( '#' + th.prop( 'id' ) + ( ( s.b == 'Just trigger' )? '' : ',#' + thL.prop( 'id' ) ) )
							.mouseenter( function( e ){
								if( s.d > 0 ){ th.trigger( 'vdSetDelay' ); }else{ th.trigger( 'vdShowElement', [ thL.prop( 'id' ) ] ); }
							})
							.mouseleave( function( e ){
								var o = $(this);
								if( ( e.pageX <= o.offset().left ) || ( e.pageX >= o.offset().left + o.width() ) || ( e.pageY <= o.offset().top ) || ( e.pageY >= o.offset().top + o.height() ) ){ th.trigger( 'vdHideElement', [ thL.prop( 'id' ), e.target.nodeName ] ); };
							});
					}
					else if( ( s.s == 'Click' ) && ( s.h == 'Mouseout' ) ){
						th.click( function( e ){ 
							if( s.d > 0 ){ th.trigger( 'vdSetDelay' ); }else{ th.trigger( 'vdShowElement', [ thL.prop( 'id' ) ] ); };
						});
						$( '#' + th.prop( 'id' ) + ( ( s.b == 'Just trigger' )? '' : ',#' + thL.prop( 'id' ) ) ).mouseleave( function( e ){
							if( ( e.pageX < th.offset().left ) || ( e.pageX > th.offset().left + th.width() ) || ( e.pageY < th.offset().top ) || ( e.pageY > th.offset().top + th.height() ) ){ th.trigger( 'vdHideElement',[ thL.prop( 'id' ), e.target.nodeName, false ] ); };
						});
					}
					else if( s.h == 'Never' ){
						if( s.s == 'Click' ){
							th.click( function( e ){
								if( s.d > 0 ){ th.trigger( 'vdSetDelay' ); }else{ th.trigger( 'vdShowElement', [ thL.prop( 'id' ) ] ); };
							});				
						}
						else if( s.s == 'Mouseover' ){
							th.mouseenter( function( e ){
								if( s.d > 0 ){ th.trigger( 'vdSetDelay' ); }else{ th.trigger( 'vdShowElement', [ thL.prop( 'id' ) ] ); };
							});
						};
					};
					if( ( s.s == 'Mouseover' ) && ( top.window.isTouchDevice ) ){
						th.bind('touchhold', function( e ){ th.trigger( 'vdShowElement', [ thL.prop( 'id' ) ] ); });
						th.unbind('mouseenter');
					};
					if( s.s == 'Load' ){
						if( s.d > 0 ){ th.trigger( 'vdSetDelay' ); }else{ th.trigger( 'vdShowElement', [ thL.prop( 'id' ) ] ); };
					};
				};
			});
			return this;
		},

		registerPopup : function( o ){
			if( ( this.length < 1 ) ){ return this; }
			var s = { i: '', c: {}, pW: 0, pH: 0, l: '#', a: '' };
			if( o ){ $.extend( s, o ); }
			this.each( function(){
				var th = $( this );
				if( th.vdCore( 'isVisible' ) ){
					var id = $.vdTools( 'getId', th.attr( 'class' ) );
					if( ! th.hasClass( 'VDRegisteredP' ) ){
						if( ! th.prop( 'id' ) ){ th.prop( 'id', id + '_' + (+new Date) ); }
						th.data('d',{
							pL: th.parent().closest( '.VD.l' )
						}).addClass( 'VDRegisteredP' );
						if( th.data('d').pL.length == 1 ){
							th.data('d').pL.trigger( 'vdRegisterOrphans', [ '#'+ th.prop( 'id' ) ] );
						};
					};
					if( $( '.' + s.i + '.VD.p' ).length > 0 ){ var thP = $( '.' + s.i + '.VD.p' ).eq( 0 );	}
					else{
						var thP = $( '<div id="p_' + s.i + '" class="' + s.i + ' VD p" style="display:none;cursor:default;overflow-y:auto;overflow-x:hidden;max-width:80%;max-height:90%;z-index:' + popupLayoutZIndex + ' !important"><div id="pl_' + s.i + '" class="l_' + s.i + ' VD l pb" style="overflow:hidden;width:0;height:0"></div></div>' );
						thP.appendTo( 'body' );
						$( '.VD.pb', thP )
							.vdCore( 'registerLayoutBox', { o: 'Resize to content', l: s.l, pW: s.pW, pH: s.pH, a: s.a } )
							.unbind( 'vdHideElement' ).bind( 'vdHideElement', function( e ){ $( '.close', thP ).eq( 0 ).click(); return false; });
					};
					s.c.target = '#p_' + s.i;
					th.overlay( s.c );
					thP.bind( 'vdLoadContent', function( e, c ){
						if( typeof c.s === 'undefined' ){ c.s = -1; }
						var x = thP.width();
						$( '.VD.pb', thP ).eq( 0 ).trigger( 'vdLoadContent', [ c ] );
						setTimeout( function(){ if( thP.width() != x ){ thP.css( 'left', ( parseInt( thP.css( 'left' ) ) + ( x - thP.width() ) / 2 ) + 'px' ); }; }, 200 );
						return false;
					});
					th.bind( 'vdRemove', function(){
						th.remove();
						if( $( '.' + id ).length < 1){ $( '.VD.pb', thP ).eq( 0 ); thP.remove(); }
					});
				};
			});
			return this;
		},
		
		registerLayoutGrid : function( o ){
			if( typeof o.ids === 'undefined' || o.ids.length < 1 ){ return this; }
			var i = 0;
			var j = 0;
			var k = 0;
			var c = 0;
			var col = $( '.VDLayoutCol', this.eq( 0 ) );
			for ( i = 0; i < o.ids.length; i++ ){
				for ( j=0; j < o.ids[ i ].length; j++ ){
					for ( k=0; k < o.ids[ i ][ j ].length; k++ ){
						$( o.ids[ i ][ j ][ k ] + '.VD.l', o.con ).appendTo( col[ c ] ).addClass( 'VDLayoutBox' );
						};
					c++;
					};
				};
			this.get( 0 ).id = this.get( 0 ).className.substring( 0, this.get( 0 ).className.indexOf( ' ' ) ) + '_' + (+new Date);
			this.get( 0 ).className += ' VDRegisteredLG';
			return this;
		},
		
		registerLayoutBox : function( o ){
			if( ( this.length !== 1 ) || ( ! this.eq( 0 ).vdCore( 'isVisible' ) ) ){ return this; }
			var s = { o: '', pW: 0, pH: 0, l: '#', a: '', h: false };
			if( o ){ $.extend( s, o ); }
			var th = this.eq( 0 );
			if( ! th.hasClass( 'VDRegisteredLB' ) ){
				if( ! th.prop( 'id' ) ){ th.prop( 'id', $.vdTools( 'getId', th.attr( 'class' ) ) + '_' + (+new Date) ); }
				th.data('d',{
					overflow: s.o,
					scrollbars: { x: ( th.css( 'overflow-x' ) == 'auto' ), y: ( th.css( 'overflow-y' ) == 'auto' ) },
					pL: th.parent().closest( '.VD.l' ),
					orphans: false,
					position: th.offset(),
					scroll: false,
					size: { height: th.height(), width: th.width() },
					vector: { x: 0, y: 0 },
					current: { l: '', a: '' },
					inner: { width: 0, height: 0 },
					history: [],
					queue: []
				}).addClass( 'VDRegisteredLB' );
				var d = th.data('d');
				if( d.pL.length == 1 ){
					d.pL.trigger( 'vdRegisterOrphans', [ '#'+ th.prop( 'id' ) ] );
				};
				th.scroll( function( e ){ $( '.onScroll' + th.prop( 'id' ) ).trigger( 'vdOnScroll' ); });
				th.bind( 'vdShowElement', function( e ){
					th.show();
					return false;
				});
				th.bind( 'vdHideElement', function( e ){
					if( this.className.indexOf(' d ') > 0 ){ th.hide(); }
					else{ th.trigger( 'vdResizeElement', [ -1 * th.width() + 1, -1 * th.height(), 0 ] ); }
					return false;
				});
				th.bind( 'vdScrollElement', function( e, v ){
					$.vdTools( 'scrollElement', [ v, th ] );
					return false;
				});
				th.bind( 'vdRegisterOrphans', function( e, t ){
					$( t ).addClass( 'removeWith' + th.prop( 'id' ) );
					d.orphans = true;
				});
				th.bind( 'vdRegisterScroll', function( e, t, f ){
					if( d.scrollbars !== { x: false, y: false } ){
						$( t ).addClass( 'onScroll' + th.prop( 'id' )  );
					};
				});
				th.bind( 'vdRemove', function(){
					if ( d.orphans ){
						$( '.removeWith' + th.prop('id') ).trigger( 'vdRemove' );
						d.orphans = false;
					};
					th.remove();
				});
				th.bind( 'vdSetScroll', function( e ){
					if( typeof d.scroll == 'object' ){
						th.scrollTop( d.scroll.top ).scrollLeft( d.scroll.left )
						d.scroll = false;
					}
				});
				th.bind( 'goTo', function( e, a ){
					$.vdTools('triggerLink',[ { l: a, t: $.vdTools( 'getId', th.attr( 'class' ) ) } ]);
				});
				if( s.h ){ return false; }
				th.bind( 'vdCheckOverflow', function( e ){
					var w = 0;
					var h = 0;
					var ot = th.offset().top;
					var ol = th.offset().left;
					var sx = ( d.scrollbars.x ) ? th.scrollLeft() : 0;
					var sy = ( d.scrollbars.y ) ? th.scrollTop() : 0;
					var p = $( '.VDPage', th ).eq( 0 );
					$( '.VD.VDLayoutGrid.VDRegisteredLG', th ).each( function(){
						if( $( this ).vdCore( 'isVisible' ) ){
							var l = $( this );
							w = Math.max( l.width() + l.offset().left - ol + sx, w );
							h = Math.max( l.height() + l.offset().top - ot + sy, h );
						};
					});
					$( '.VD.l.VDRegisteredLB', th ).each( function(){
						if( ( this.className.indexOf( 'VDLayoutBox' ) < 0 ) && ( $( this ).vdCore( 'isVisible' ) ) ){
							var l = $( this );
							w = Math.max( l.data('d').size.width + l.offset().left - ol + sx, w );
							h = Math.max( l.data('d').size.height + l.offset().top - ot + sy, h );
						};
					});
					w = Math.max( Math.min( d.inner.width, p.width() ), w );
					h = Math.max( Math.min( d.inner.height, p.height() ), h );
					if( d.overflow == 'Fixed size' ){
						th.vdCore( 'postponeAction', 'vdResizePage', function(){ p.css( { 'width': w, 'height': h, 'overflow': 'hidden' } ); });
					}
					else{
						if( d.overflow === 'Resize vertically' ){ w = th.width(); }
						else if( d.overflow === 'Resize horizontally' ){ h = th.height(); }
						if ( w != th.width() || h != th.height() ){
							d.size = { width: w, height: h };
							th.trigger( 'vdOnResize' );
							th.trigger( 'vdResizeElement', [ w - th.width(), h - th.height() ] );
						};
					};
					return false;
				});
				th.bind( 'vdGoBack', function(){ 
					if( d.history.length > 1 ){
						d.history.pop();
						th.trigger( 'vdLoadContent', [ d.history.pop() ] );
					};
					return false;
				});
				th.bind( 'vdLoadContent', function( e, cc ){
					var c = { l: '#', a: '', pW: 0, pH: 0, s: 100, h: 'Yes' };
					if( cc ){ $.extend( c, cc ); }
					// backward compatibility -remove 10.2011
						c.h = c.h.charAt(0).toUpperCase() + c.h.substring(1);
					// -end
					if( c.l == '' || c.l == '#' || ( c.l == d.current.l && c.a == d.current.a ) ){ return false; };
					if( c.h != 'No' ){ d.history.push( { l: c.l, a: c.a, pW: c.pW, pH: c.pH, s: c.s } ); };
					d.current = { l: c.l, a: c.a };
					if( c.s > 0 ){ th.append( '<img src="../img/loading.gif" class="VD throbber" />' ); }
					if ( d.orphans ){
						$( '.removeWith' + th.prop( 'id' ) ).trigger( 'vdRemove' );
						d.orphans = false;
					};
					$.get( ( ( c.l.indexOf( 'page_' ) === 0 )? c.l + '.ajax' : c.l ), function( data ){
						th.html( '<div style="position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:white"></div>' );
						var m = $( 'div', th ).eq( 0 );
						m.before( data );
						if( $( '.VDPage', th ).length === 0 ){ m.remove(); return false; }
						th.trigger( 'vdOnChanging' );						
						var w = d.size.width;
						var h = d.size.height;
						if( c.a != '' ){
							var i = '';
							var an;
							if( c.a.indexOf( '#' ) > -1 ){ c.a = c.a.replace( ' ', '' ).split( '#' ); i = c.a[ 1 ]; c.a = c.a[ 0 ]; }
							if( c.a != '' ){
								an = $( '.' + c.a, th ).eq( 0 );
								if( typeof an.get(0) === 'undefined' ){ alert("PROTOTYPE ERROR: There is a link pointing to a missing shape Id: '"+c.a+"'."); return false; }
								if( an.get( 0 ).className.indexOf( 'VD co' ) > -1 ){
									w = parseInt( an.css( 'width' ) );
									h = parseInt( an.css( 'height' ) );
									$( '.VDPage', th ).eq( 0 ).css( { 'width': w, 'height': h, 'overflow': 'hidden' } );
									$( '.VDPage > .VDCanvas', th ).eq( 0 ).css( { 'margin-left': '-' + an.css( 'left' ), 'margin-top': '-' + an.css( 'top' ) } );
									if( top.window.isTouchDevice ){ $( '.VDPage > .VDCanvas', th ).eq( 0 ).addClass( 'VDCanvas_' + $.vdTools( 'getId', an.get( 0 ).className ) ); };
									th.scrollTop( 0 );
								}
								else if( i == ''){ i = c.a; }
							}
							if( i != '' ){
								an = $( '.' + i, th ).eq( 0 );
								if( typeof an.get(0) === 'undefined' ){ alert("PROTOTYPE ERROR: There is a link pointing to a missing anchor Id: '"+i+"'."); return false; }
								d.scroll = { top: parseInt( an.css( 'top' ) ), left: parseInt( an.css( 'left' ) ) };
								if( $( '.VD.l', th ).length < 1 ){ th.trigger( 'vdSetScroll' ); }
								else{ th.vdCore( 'postponeAction', 'vdSetScroll', function(){ th.trigger( 'vdSetScroll' ); }); };
							};
						}
						else{ 
							w = c.pW;
							h = c.pH;
							th.scrollTop( 0 ); 
						};
						d.inner = { width: w, height: h };
						m.remove();
						if( d.overflow !== 'Fixed size' ){
							d.size = { width: w, height: h };
							d.vector.x = w - th.width();
							d.vector.y = h - th.height();
							if( d.overflow === 'Resize vertically' ){ d.vector.x = 0; }
							else if( d.overflow === 'Resize horizontally' ){ d.vector.y = 0; }
							if( d.vector.x !=0 || d.vector.y != 0 ){ th.trigger( 'vdResizeElement', [ d.vector.x, d.vector.y, c.s ] ); };
						};
						$(document).trigger( $( '.VDPage', th ).eq( 0 ).attr( 'class' ).substring( 7 ) + 'ready', [ th ] );
						th.trigger( 'vdOnChanged' );
						return false;
					},
					'html' );
				return false;
				});	
				th.bind( 'vdResizeElement', function( e, vx, vy, s ){
					if( typeof s == 'undefined' ){ s = 100; }
					var ch = { height: parseInt( th.css( 'height' ) ) + vy + 'px', width: parseInt( th.css( 'width' ) ) + vx + 'px' };
					if( s > 0 ){
						th.animate( ch, s, 'swing', function(){ 
							th.vdCore( 'postponeAction', 'vdResizePage', function(){ $( '.VDPage', th ).eq( 0 ).css( { 'width': parseInt( ch.width ), 'height': parseInt( ch.height ), 'overflow': 'hidden' } ); });
							if( d.pL.length == 1 ){
								d.pL.trigger( 'vdCheckOverflow' );
								if( typeof d.pL.data('d').scroll == 'object' ){
									d.pL.vdCore( 'postponeAction', 'vdSetScroll', function(){ th.trigger( 'vdSetScroll' ); });
								};
							};
						});
					}
					else{
						th.css( ch );
						th.vdCore( 'postponeAction', 'vdResizePage', function(){ $( '.VDPage', th ).eq( 0 ).css( { 'width': parseInt( ch.width ), 'height': parseInt( ch.height ), 'overflow': 'hidden' } ); });
						if( d.pL.length == 1 ){
							d.pL.trigger( 'vdCheckOverflow' ); 
							if( typeof d.pL.data('d').scroll == 'object' ){
								d.pL.vdCore( 'postponeAction', 'vdSetScroll', function(){ th.trigger( 'vdSetScroll' ); });
							};
						};
					};
				return false;
				});
				th.trigger( 'vdLoadContent', [ { l: s.l, a: s.a, pW: s.pW, pH: s.pH, s: -1 } ] );
				if( d.pL.length == 1 ){ d.pL.trigger( 'vdCheckOverflow' ); };
			};
			return this;
		},
		
		rememberValue : function( o ){
			if( this.length !== 1 ){ return this; }
			var th = this.eq( 0 );
			if( ! th.vdCore( 'isVisible' ) ){ return this; }
			if( ! th.attr( 'name' ) ){
				alert( "Please set up a 'Name' property in all fields you want to remember values for. Fields that are missing this property and yet are set up to remember their values have been marked with a red outline." );
				th.css('border','2px solid red'); 
				return this;
				};
			th.bind( 'vdSaveValue', function(){
				var n = '', v = '';
				n = th.attr( 'name' );
				if( typeof n === 'string' && n !== '' ){
					if( th.is( ':checkbox' ) ){ v = ( th.prop( 'checked' ) )? 'true' : 'false'; }
					else if( th.attr( 'multiple' ) ){ $('option:selected', th).each( function(){ v += 'VAL::' + this.value; }); }
					else{ v = th.val(); };
					if( typeof v !== 'string' ){ v = ''; };
					if( th.data('label') !== undefined && v == th.data('label') ){ v = ''; }
					if( top.window.localStorage ){ top.window.localStorage.setItem( n, v ); }
				};
			});
			th.bind( 'vdLoadValue', function(){
				var n = '', v = null;
				n = th.attr( 'name' );
				if( typeof n === 'string' && n !== '' ){
					if( top.window.localStorage ){ v = top.window.localStorage.getItem( n ); };
					if( typeof v !== 'string' ){ v = ''; }
					if( v === '' && typeof th.data('label') !== undefined && th.val() == th.data('label') ){ v = th.data('label'); }
					if( th.is( ':radio' ) ){ th.prop( 'checked', ( th.val() == v )? true : false ); }
					else if( th.is( ':checkbox' ) ){ th.prop( 'checked', ( v == 'true' )? true: false ); }
					else if( th.attr( 'multiple' ) ){ $( 'option[value="' + v.substring( 7 ).split( 'VAL::' ).join( '"], option[value="' ) + '"]' ).prop( 'selected', true ); }
					else{ th.val( v ); };
				};
			});
			if( typeof o === 'undefined' ){ th.trigger( 'vdLoadValue' ); }
			else { th.prop( 'value', o ); };
			th.change( function(){ th.trigger( 'vdSaveValue' ); });
			return this;
		},
		
		touchScroll : function( o ){
			this.each( function(){
				var th = $( this );
				var d = th.data('d');
				if( th.vdCore( 'isVisible' ) !== true ){ return true; }
				var ovX = ( typeof d == 'undefined' ) ? ( th.css( 'overflow-x' ) == 'auto' ) : d.scrollbars.x;
				var ovY = ( typeof d == 'undefined' ) ? ( th.css( 'overflow-y' ) == 'auto' ) : d.scrollbars.y;
				if( ovX || ovY ){
					th.css({ 'overflow-x': 'hidden', 'overflow-y': 'hidden' });
					d.scrollbars = { x: ovX, y: ovY };
					var sc = { 
						maxX: 0, posX: 0, ranX: 0, lenX: 0, curX: 0, barX: null, isX: false,
						maxY: 0, posY: 0, ranY: 0, lenY: 0, curY: 0, barY: null, isY: false
						};
					var to = { spoX: 0, lpoX: 0, spoY: 0, lpoY: 0 };
					var ev;
					var lw = th.width();
					var lh = th.height();
					var thO = th.get( 0 );
					var scrolling = false;
					if( !window.isTouchDevice ){
						th.css( 'cursor', 'pointer' );
						this.addEventListener( 'click', function( e ){
							e.preventDefault();
							e.stopPropagation();
						}, true );
						th.bind( 'mouseleave', function( e ){
							scrolling = false;
						});
					};
					this.addEventListener( ( top.window.isTouchDevice ) ? 'touchstart' : 'mousedown', function( e ){
						th.stop();
						if( e.target.nodeName == 'INPUT' || e.target.nodeName == 'SELECT' || e.target.nodeName == 'TEXTAREA' ){
							e.stopPropagation();
						}
						else{
							ovX = d.scrollbars.x;
							ovY = d.scrollbars.y;
							to.spoX = to.lpoX = ( top.window.isTouchDevice ) ? e.touches[0].pageX : e.pageX;
							to.spoY = to.lpoY = ( top.window.isTouchDevice ) ? e.touches[0].pageY : e.pageY;
							if( ovX ){
								lw = th.width();
								sc.maxX = thO.scrollWidth - lw;
								if( sc.maxX < 1 ){ ovX = false; }
								else{
									sc.curX = thO.scrollLeft + ( ( top.window.isTouchDevice ) ? e.touches[0].pageX : e.pageX );
									sc.ranX = thO.scrollWidth;
									sc.lenX = lw * lw / sc.ranX;
								};
							}
							if( ovY ){
								lh = th.height();
								sc.maxY = thO.scrollHeight - lh;
								if( sc.maxY < 1 ){ ovY = false; }
								else{
									sc.curY = thO.scrollTop + ( ( top.window.isTouchDevice ) ? e.touches[0].pageY : e.pageY );
									sc.ranY = thO.scrollHeight;
									sc.lenY = lh * lh / sc.ranY;
								};
							}
							ev = e;
							scrolling = true;
							e.preventDefault();
						};
					}, false );
					this.addEventListener( ( top.window.isTouchDevice ) ? 'touchmove' : 'mousemove', function( e ){
						if( scrolling ){
							to.lpoX = ( top.window.isTouchDevice ) ? e.touches[0].pageX : e.pageX;
							to.lpoY = ( top.window.isTouchDevice ) ? e.touches[0].pageY : e.pageY;
							if( ovX ){
								thO.scrollLeft = Math.min( ( sc.curX - ( ( top.window.isTouchDevice ) ? e.touches[0].pageX : e.pageX ) ), sc.maxX );
								sc.posX = thO.scrollLeft + ( thO.scrollLeft * lw / sc.ranX );
							};
							if( ovY ){
								thO.scrollTop = Math.min( ( sc.curY - ( ( top.window.isTouchDevice ) ? e.touches[0].pageY : e.pageY ) ), sc.maxY );
								sc.posY = thO.scrollTop + ( thO.scrollTop * lh / sc.ranY );
							};
							if( ovX ){
								if( sc.isX ){ sc.barX.css( { 'left': sc.posX + 'px', 'top': ( thO.scrollTop + lh - 7 ) } ); }
								else if( sc.lenX < lw ){
									sc.barX = $( '<div style="border-radius:3px;background:#5D5D5D;border:1px solid #CCCCCC;opacity:0.75;position:absolute;top:' + ( th.offset().top + lh - 7 ) + 'px;left:' + sc.posX + 'px;height:4px;width:' + sc.lenX + 'px;' + o.c + '"></div>' );
									sc.barX.appendTo( th );
									sc.isX = true;
								};
							};
							if( ovY ){
								if( sc.isY ){ sc.barY.css( { 'top': sc.posY + 'px', 'left': ( thO.scrollLeft + lw - 7 ) } ); }
								else if( sc.lenY < lh ){
									sc.barY = $( '<div style="border-radius:3px;background:#5D5D5D;border:1px solid #CCCCCC;opacity:0.75;position:absolute;top:' + sc.posY + 'px;left:' + ( th.offset().left + lw - 7 ) + 'px;height:' + sc.lenY + 'px;width:4px;' + o.c + '"></div>' );
									sc.barY.appendTo( th );
									sc.isY = true;
								};
							};
							e.preventDefault();
						};
					}, false );
					this.addEventListener( ( top.window.isTouchDevice ) ? 'touchend' : 'mouseup', function( e ){
						if( Math.abs( to.lpoX - to.spoX ) < 10 && Math.abs( to.lpoY - to.spoY ) < 10 ){
							var ob = ( ( typeof ev.target.className == 'string' && ev.target.className.indexOf( ' VD ' ) > 0 ) || ev.target.nodeName == 'A' )? ev.target: ( ( ev.target.parentNode.nodeName == 'A' )? ev.target.parentNode : undefined );
							if( typeof ob !== 'undefined' ){
								if( e.timeStamp - ev.timeStamp > 500 ){ $( ob ).trigger( 'touchhold' ); }
								else{ $( ob ).trigger( 'click' ); };
							};
							try{ sc.isX = false; sc.barX.remove(); sc.barX = null; }catch(r){};
							try{ sc.isY = false; sc.barY.remove(); sc.barY = null; }catch(r){};
						}
						else{
							var speedX = ( ovX ) ? ( to.spoX - to.lpoX ) / ( e.timeStamp - ev.timeStamp ) / ( ( top.window.isTouchDevice ) ? 1 : 2 ) : 0;
							var speedY = ( ovY ) ? ( to.spoY - to.lpoY ) / ( e.timeStamp - ev.timeStamp ) / ( ( top.window.isTouchDevice ) ? 1 : 2 ) : 0;
							if( Math.abs( speedX ) > 0.1 || Math.abs( speedY ) > 0.1 ){
								th.animate(
									{
										scrollLeft: '+=' + ( speedX * 1000 ),
										scrollTop: '+=' + ( speedY * 1000 )
									},
									{
										duration: 2000, 
										easing: 'easeOutCirc',
										step: function(){
											if( ovX ){
												if( thO.scrollLeft + lw > sc.ranX ){
													try{ sc.isX = false; sc.barX.remove(); sc.barX = null; }catch(r){};
													try{ sc.isY = false; sc.barY.remove(); sc.barY = null; }catch(r){};
													th.scrollLeft( sc.ranX - lw ).stop();
												}
												else if( thO.scrollLeft < 1 ){
													try{ sc.isX = false; sc.barX.remove(); sc.barX = null; }catch(r){};
													try{ sc.isY = false; sc.barY.remove(); sc.barY = null; }catch(r){};
													th.scrollLeft( 0 ).stop();
												}
												else{
													sc.posX = thO.scrollLeft + ( thO.scrollLeft * lw / sc.ranX );
													sc.barX.css( { 'left': sc.posX + 'px', 'top': ( thO.scrollTop + lh - 7 ) } );
												};
											};
											if( ovY ){
												if( thO.scrollTop + lh > sc.ranY ){
													try{ sc.isX = false; sc.barX.remove(); sc.barX = null; }catch(r){};
													try{ sc.isY = false; sc.barY.remove(); sc.barY = null; }catch(r){};
													th.scrollTop( sc.ranY - lh ).stop();
												}
												else if( thO.scrollTop < 1 ){
													try{ sc.isX = false; sc.barX.remove(); sc.barX = null; }catch(r){};
													try{ sc.isY = false; sc.barY.remove(); sc.barY = null; }catch(r){};
													th.scrollTop( 0 ).stop();
												}
												else{
													sc.posY = thO.scrollTop + ( thO.scrollTop * lh / sc.ranY );
													sc.barY.css( { 'top': sc.posY + 'px', 'left': ( thO.scrollLeft + lw - 7 ) } );
												};
											};
										},
										complete: function(){
											try{ sc.isX = false; sc.barX.remove(); sc.barX = null; }catch(r){};
											try{ sc.isY = false; sc.barY.remove(); sc.barY = null; }catch(r){};
										}
									}
								);
							}
							else{
								try{ sc.isX = false; sc.barX.remove(); sc.barX = null; }catch(r){};
								try{ sc.isY = false; sc.barY.remove(); sc.barY = null; }catch(r){};
							};
							$( '.onScroll'+th.prop( 'id' ) ).trigger( 'vdOnScroll' ); 
						}
						delete ev;
						scrolling = false;
						e.preventDefault();
					}, false );
				};
			});
		},

		registerValidation : function( o ){
			if( this.length !== 1 ){ return this; }
			var s = { t: '', m: '', r: '', i: '' };
			if( o ){ $.extend( s, o ); };
			if( s.m == '' || s.m == "Don't validate" ){ return this; }
			var th = this.eq( 0 );
			var css = { top: th.css('top'), left: th.css('left'), 'margin-top': th.css( 'height' ), width: th.css( 'width' ), 'margin-left': '10px' };
			if( th.is( ':checkbox' ) || th.is( ':radio' ) ){ css.width = th.prev('label').eq(0).css('width'); };
			var con = ( ( th.parent().closest( '.VD.l' ).length == 1 )? '_' + th.parent().closest( '.VD.l' ).eq( 0 ).prop( 'id' ) : '' );
			var res = false;
			var vli = $( document.createElement( 'div' ) ).attr( 'class', 'v_' + s.t + con + ' VD fv h' ).css( css ).html( s.i );
			$( document.createElement( 'img' ) ).attr({ 'alt': 'Close', 'title': 'Close', 'src': '../img/validationClose.gif' }).click( function(){ vli.hide(); }).appendTo( vli );
			th.before( vli ).focus( function(){ vli.hide(); });
			if( s.m == 'Validate inline' || s.m == 'Use both' ){ th.blur( function(){ th.trigger( 'vdValidate' ); }); }
			if( s.m == 'Validate on submit' || s.m == 'Use both' ){ th.addClass( 'VDValidate' ); }
			th.bind( 'vdValidate', function(){
				var val = th.val();
				if( typeof val !== 'string' ){ val = ''; }
				if( th.data('label') !== undefined && val == th.data('label') ){ val = ''; }
				try{
					if( th.is( ':checkbox' ) ){ if( th.prop( 'checked' ) ){ return ''; }else{ vli.show(); return 'f'; };}
					if( ! s.r.test( val ) ){ vli.show(); return 'f'; }else{ return ''; }
				}catch(e){ return 'f'; }
				return 'f';
			});
			return this;
		}
	}
	
	$.fn.vdCore = function( method ){
		if( this.length < 1 ){ return false; }
		if( methods[ method ] ){ return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); }
		else{ $.error( 'Method ' +  method + ' does not exist on jQuery.vdCore' ); }
	};

})( jQuery );

$(window).bind( 'vdScrollElement', function( e, v ){
	$.vdTools( 'scrollElement', [ v, $('html,body') ] );
	return false;
});

if( top.window.isTouchDevice && top.window.name=='VisDynamica Mobile View' ){
	$.vdTools( 'hideMobileAddressBar' );
};
