/*
 *
 * Copyright (c) 2007 e-nova technologies pvt. ltd. (kevin.muller@enova-tech.net || http://www.enova-tech.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.
 *            __             ___      ___    __  __     __
 *          /'__`\    __   /' _ `\   / __`\ /\ \/\ \  /'__`\
 *         /\  __/  /\__\  /\ \/\ \ /\ \_\ \\ \ \_/ |/\ \_\.\_
 *  (o_    \ \____\ \/__/  \ \_\ \_\\ \____/ \ \___/ \ \__/.\_\    _o)
 *  (/)_    \/____/         \/_/\/_/ \/___/   \/__/   \/__/\/_/   _(\)
 *
 *           Prevents Headaches !
 *
 * JMyCarousel is inspired and based on JCarouselLite, an original concept by Ganeshji Marwaha
 *
 *
 * $LastChangedDate: 2007-06-22 20:08:34 -0500 (Thu, 22 Nov 2007) $
 * $Rev: 15 $
 *
 * Version: 0.1
 */

(function ( $ ) {                  // Compliant with jquery.noConflict()
$.fn.jMyCarousel = function(o) {
    o = $.extend({
        btnPrev: null,			// previous button customization
        btnNext: null,			// next button customization
        mouseWheel: true,		// shall the carousel handle the mousewheel event to animate ?
        auto: false,			// shall the carousel start automatically

        speed: 500,				// speed in ms of the animation.
        easing: 'linear',		// linear animation.

        vertical: false,		// set the carousel in a vertical mode
        circular: true,			// run in circular mode. Means : images never reach the end.
        visible: '4',			// size of the carousel on the screen. Can be in percent '100%', in pixels '100px', or in images '3' (for 3 images)
        start: 0,				// position in pixels that the carousel shall start at
        scroll: 1,

        step: 50,				// value in pixels, or "default"
        eltByElt: false,		// if activated, the carousel will move image by image, not more, not less.
        evtStart : 'mouseover',	// start event that we want for the animation (click, mouseover, mousedown, etc..)
		evtStop : 'mouseout',	// stop event that we want for the animation (blur, mouseout, mouseup, etc..)
        beforeStart: null,		// Not used yet
        afterEnd: null			// Not used yet
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.
        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;
        var mousewheelN = 0; // will help for the mousewheel effect (to count how many steps we have to walk ahead)
		var defaultBtn = (o.btnNext === null && o.btnPrev === null) ? true : false;
		var cssU = (v.toString().indexOf("%") != -1 ? '%' : (v.toString().indexOf("px") != -1) ? 'px' : 'el');
		var direction = null; // used to keep in memory in which direction the animation is moving

        // circular mode management
        // we add at the end and at the beginning some fake images to make the circular effect more linear, so it never breaks
        // It is still possible to improve the memory management by adding exactly the number of images requested.
        if(o.circular) {
			var imgSet = tLi.clone();
            ul.prepend(imgSet).append(imgSet.clone());
        }

		var li = $("li", ul);								// list
        div.css("visibility", "visible");
        li.css("overflow", "hidden")                        // If the list item size is bigger than required
            .css("float", o.vertical ? "none" : "left")     // Horizontal list
            .children().css("overflow", "hidden");          // If the item within li overflows its size, hide'em
        if(!o.vertical){ li.css("display", "inline"); }		// IE double margin bug - rooo..
        if(li.children().get(0).tagName.toLowerCase() == 'a' && !o.vertical){
        	li.children().css('float','left');
        }
        if(o.vertical && jQuery.browser.msie){				// Hack IE (again..) / purpose is to cancel the white space below the image when the carousel is in vertical mode
        													// The issue comes up when li is not in float:left. so we put it in float:left and adjust the size
        	li.css('line-height', '4px').children().css('margin-bottom', '-4px');
        }


        ul.css("margin", "0")                               // Browsers apply default margin
            .css("padding", "0")                            // and padding. It is reset here.
            .css("position", "relative")                    // IE BUG - width as min-width
            .css("list-style-type", "none")                 // We dont need any icons representing each list item.
            .css("z-index", "1");                           // IE doesnt respect width. So z-index smaller than div

        div.css("overflow", "hidden")                       // Overflows - works in FF
            .css("position", "relative")                    // position relative and z-index for IE
            .css("z-index", "2")                            // more than ul so that div displays on top of ul
            .css("left", "0px");                            // after creating carousel show it on screen

        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var liSizeV = o.vertical ? elHeight(li) : height(li);	// size of the main layer, in its side
        var curr = o.start;   								// Current position in pixels
        var nbAllElts = li.size();							// Total number of items
        var ulSize = liSize * nbAllElts;                   	// size of full ul(total length, not just for the visible items)
        var nbElts = tl;									// number of elements (only visible items)
        var eltsSize = nbElts * liSize;						// size of the visible elements only
        var allEltsSize = nbAllElts * liSize;				// Total size of the elements
        //var jmcSize = jmcSize();							// Size of the carousel
        var step = o.step == 'default' ? liSize : o.step;	// step size

        //debug("liSize=" + liSize + "; liSizeV=" + liSizeV + "; curr=" + curr + "; visible : " + liSize * v); // debug
  		o.btnPrev = defaultBtn ? $('<input type="button" class="' + (o.vertical ? 'up' : 'prev') + '" />') : $(o.btnPrev);
  		o.btnNext = defaultBtn ? $('<input type="button" class="' + (o.vertical ? 'down' : 'next') + '" />') : $(o.btnNext);
        var prev = o.btnPrev;
        var next = o.btnNext;

        /******* Buttons **********/
        if(defaultBtn && o.auto !== true){ 					//Add buttons when necessary (In default mode and not auto)
	        prev.css({'opacity':'0.6'});
	        next.css({'opacity' :'0.6'});
	        div.prepend(prev);
	        div.prepend(next);
	        o.btnPrev = prev;
	        o.btnNext = next;
        }

        // Element by element management (eltBYElt = true)
        if(o.eltByElt){
        	step = liSize;									// the step size is necessarily the size of the element
        	if(o.start % liSize !== 0){						// If a start position was given and was not exactly positionned between 2 images
        		var imgStart = parseInt(o.start / liSize);	// we adjust it
        		curr = o.start = (imgStart * liSize);		// we set the starting position at a fixed point, between 2 images.
        	}
        }

        // Adjust the start position in case of circular mode
        if(o.circular){
        	o.start += (liSize * tl);  						// The start position is one carousel length ahead due to the optical effect
        	curr += (liSize * tl);							// used for the animation
        }

        // Calculates the size of the main div according to the given size (can be in percent, in value or in pixels)
        var divSize, cssSize, cssUnity;
        if(cssU == '%'){									// in percent
        	divSize = 0;									// We don't have the value in pixels unless we set the percent value first. So 0, and will catch it later
        	cssSize = parseInt(v);
       		cssUnity = "%";
        }
        else if(cssU == 'px'){									// in pixels
        	divSize = parseInt(v);
        	cssSize = parseInt(v);
        	cssUnity = "px";
        }
        else{													// in elements (number of elements to display)
        	divSize = liSize * parseInt(v);
        	cssSize = liSize * parseInt(v);
        	cssUnity = "px";
        }

		// Adjust the carousel size with the correct values
        //li.css("width", imgSize(li, 'width'))              	// inner li width. this is the box model width
          //.css("height", imgSize(li), 'height');           	// inner li height. this is the box model height
        ul.css(sizeCss, ulSize + "px")                       	// Width of the UL is the full length for all the images
            .css(animCss, -(o.start));                  	 	// Set the starting item
        div.css(sizeCss, cssSize + cssUnity);                	// Width of the DIV. length of visible images
        if(o.vertical && cssUnity == '%'){						// Bugfix - % in vertical mode are badly handled by the browsers
        	var pxsize = ((liSize * nbElts) * (parseInt(v) / 100));
        	div.css(sizeCss,  pxsize + 'px');					// The height of the carousel is based on the visible elements size
        }

		if(divSize === 0){										// We didn't have the size in pixels in case of % size. Catch up !
			divSize = div.width();								// The size is simply the calculated size in pixels
		}

		// Adjust the height of the carousel (width in vertical mode)
		if(o.vertical){											// vertical mode
		    div.css("width" , liSizeV + 'px');
		    ul.css("width", liSizeV + 'px');
		    li.css('margin-bottom', (parseInt(li.css('margin-bottom')) * 2) + 'px');	// bypass the "margin collapsing" effect by multiplying the margin-bottom by 2
		    li.eq(li.size() - 1).css('margin-bottom', li.css('margin-top'));			// Last element has to be the right margin since no margin collapse there
		}else{													// horizontal mode
			div.css('height', liSizeV + 'px');
			ul.css('height', liSizeV + 'px');
		}

		// Calculate the number of visible elements inside (in case of size in percent)
		if(cssU == '%'){
			v = divSize / li.width();
			if(v % 1 !== 0){ v +=1; }
			v = parseInt(v);
		}

		var divVSize = div.height();													// div height

		////////////////////////
		// Buttons management //
		////////////////////////
		if(defaultBtn){
			next.css({'z-index':200, 'position':'absolute'});
	        prev.css({'z-index':200, 'position':'absolute'});
			//Positionate the arrows and adjust the arrow images
			if(o.vertical){
	        	prev.css({'width': prev.width(), 'height' : prev.height(), 'top' : '0px', 'left': parseInt(liSizeV / 2) - parseInt(prev.width() / 2) + 'px'});
	        	next.css({'width': prev.width(), 'height' : prev.height(), 'top' : (divVSize - prev.height()) + 'px', 'left' : parseInt(liSizeV / 2) - parseInt(prev.width() / 2) + 'px'});

	        }
	        else{
	        	prev.css({'left':'0px', 'top': parseInt(liSizeV / 2) - parseInt(prev.height() / 2) + 'px'});
	        	next.css({'right':'0px', 'top': parseInt(liSizeV / 2) - parseInt(prev.height() / 2) + 'px'});
	        }
		}

		// Bind the events with the "previous" button
        if(o.btnPrev){
            $(o.btnPrev).bind(o.evtStart, function() {
                if(defaultBtn){ o.btnPrev.css('opacity',0.9); }
                running = true;
                direction = 'backward';
                return backward();
            });

            $(o.btnPrev).bind(o.evtStop, function() {
            	if(defaultBtn){ o.btnPrev.css('opacity',0.6); }
            	running = false;
            	direction = null;
                return stop();
            });
        }


        // Bind the events with the "next" button
        if(o.btnNext){
			$(o.btnNext).bind(o.evtStart, function() {
				if(defaultBtn){ o.btnNext.css('opacity',0.9); }
				running = true;
				 direction = 'forward';
                return forward();
            });
			$(o.btnNext).bind(o.evtStop,function() {
				if(defaultBtn){ o.btnNext.css('opacity',0.6); }
				running = false;
				direction = null;
                return stop();
            });
        }

       // auto scroll management (auto = true). => launch the animation
	   if(o.auto === true){
	   	 running = true;
	   	 forward();
	   }

		// Mousewheel management
        if(o.mouseWheel && div.mousewheel){
            div.mousewheel(function(e, d) {
                if(!o.circular && (d > 0 ? (curr + divSize < ulSize) : (curr > 0)) || o.circular){ //prevents the mouse events to occur in case of circular mode
	                mousewheelN += 1; 				//one more step to do, store it.
	                if(running === false){
	                	if(d > 0){ forward(step, true); }
	                	else { backward(step, true); }
	                	running = true;
	                }
                }
            });
        }

		/**
		 * Animate the track by moving it forward according to the step size and the speed
		 * @param stepsize, the size of the step (optional)
		 * @param once, shall the animation continue endlessly until we set running to false ? (optional)
		 */
        function forward(stepsize, once){
    		var s = (stepsize ? stepsize : step);

			if(running === true && direction === "backward"){ return; }

    		//If not circular, no need to animate endlessly
    		if(!o.circular){
    			//will the next step overtake the last  image ?
    			if(curr + s + (o.vertical ? divVSize : divSize) > eltsSize){
    				s = eltsSize - (curr + (o.vertical ? divVSize : divSize));
    			}
    		}

    		ul.animate(
                animCss == "left" ? { left: -(curr + s) } : { top: -(curr + s) } , o.speed, o.easing,
                function() {
                	curr += s; //Add step size
                	//Calculate whether we cross the limit,
                	//if so, put the carousel one time backward
                	if(o.circular){
	                	if(curr + (o.vertical ? divVSize : divSize) + liSize >= allEltsSize){
	                    	ul.css(o.vertical ? 'top' : 'left', -curr + eltsSize);
	                    	curr -= eltsSize;
	                    }
                	}

                    if(!once && running){
                    	 forward();
                    }
                    else if(once){
                    	if(--mousewheelN > 0){
                    		this.forward(step, true);
                    	}
                    	else{
                    		 running = false;
                    		 direction = null;
                    	}
                    }
                }
            );
        }

        /**
         * Animate the track by moving it backward according to the step size and the speed
         * @param stepsize, the size of the step (optional)
		 * @param once, shall the animation continue endlessly until we set running to false ? (optional)
         */
        function backward(stepsize, once){
    		var s = (stepsize ? stepsize : step);

    		if(running === true && direction === "forward"){ return; }

    		//If not circular, no need to animate endlessly
    		if(!o.circular){
    			//will the next step overtake the first image ?
    			if(curr - s  < 0){
    				 s = curr - 0;
    			}
    		}

    		ul.animate(
                animCss == "left" ? { left: -(curr - s) } : { top: -(curr - s) } , o.speed, o.easing,
                function() {
                	curr -= s;
                	//Calculate if we cross the limit,
                	//if so, put the carousel one time backward
                    if(o.circular){
	                	if(curr <= liSize){
	                    	ul.css(o.vertical ? 'top' : 'left', -(curr + eltsSize));
	                    	curr += eltsSize;
	                    }
                    }

					if(!once  && running){
						backward();
					}
					else if(once){
	                	if(--mousewheelN > 0){
	                		backward(step, true);
	                	}
	                	else{
	                		 running = false;
	                		 direction = null;
	                	}
                	}
                }
            );
        }
         /**
          * Stops the animation
          * Basically, tells the animation not to continue
          */
        function stop(){
        	if(!o.eltByElt){ 	//If we don't move elements by elements, then we can stop immediately
        		ul.stop(); 		// stop the animation straight
        		curr = 0 - parseInt(ul.css(animCss));	// We stopped suddenly, so the curr variable is not refreshed. We refresh it with the true value
        	}
        	running = false; 	// default value and in case we proceed element by element (eltByElt = true)
        	direction = null;
        }

        /**
         * Return the size of the carousel, everything included (height or length depending on o.vertical)
         */
        /*function jmcSize(){
        	var img = $('ul li img', div);
        	var sizeLi = (o.vertical ? img.width() : img.height());
        	var elt = img;
        	while(elt.parent().get(0).tagName.toLowerCase() != 'div'){
        		sizeLi += (o.vertical ? (parseInt(elt.css('marginLeft')) + parseInt(elt.css('marginRight')) + parseInt(elt.css('paddingRight')) + parseInt(elt.css('paddingLeft'))) : (parseInt(elt.css('marginTop')) + parseInt(elt.css('marginBottom')) + parseInt(elt.css('paddingTop')) + parseInt(elt.css('paddingBottom'))));
        		elt = elt.parent();
        	}
        	return sizeLi;
        }*/

        /**
         * Calculate and return the size of the image in the element
         * @param el, the element
         * @param dimension, 'width' or 'height'.
         * @return the requested size in pixels.
         */
        function imgSize(el, dimension){
			if(dimension == 'width'){
				return el.find('img').width();
			}
			else {
				return el.find('img').height();
			}
		}

		/**
		 * Size of an element li with its margin calculated from scratch (without any call to width except for the image size)
		 * usefull in case of vertical carousel, when the size of each element is 100%.
		 * @param el, the element
		 * @return the size of the element in pixels
		 */
		function elHeight(el){
			var elImg = el.find('img');
			if(o.vertical){
		    	return parseInt(el.css('margin-left')) + parseInt(el.css('margin-right')) + parseInt(elImg.width()) + parseInt(el.css('border-left-width')) + parseInt(el.css('border-right-width')) + parseInt(el.css('padding-right')) + parseInt(el.css('padding-left'));
			}
			else{
				return parseInt(el.css('margin-top')) + parseInt(el.css('margin-bottom')) + parseInt(elImg.width()) + parseInt(el.css('border-top-height')) + parseInt(el.css('border-bottom-height')) + parseInt(el.css('padding-top')) + parseInt(el.css('padding-bottom'));
			}
		}

        function debug(html){
        	$('#debug').html($('#debug').html() + html + "<br/>");
        }

    });
};

function css(el, prop) {
    return parseInt($.css(el[0], prop)) || 0;
}

function width(el) {
    	return el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
}

function height(el) {
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
}

})(jQuery);

/*
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 *
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 *
 * Version: 1.3.1 (05/03/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

(function($) {

	var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right,

		selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],

		ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,

		loadingTimer, loadingFrame = 1,

		start_pos, final_pos, busy = false, shadow = 20, fx = $.extend($('<div/>')[0], { prop: 0 }), titleh = 0,

		isIE6 = !$.support.opacity && !window.XMLHttpRequest,

		/*
		 * Private methods
		 */

		fancybox_abort = function() {
			loading.hide();

			imgPreloader.onerror = imgPreloader.onload = null;

			if (ajaxLoader) {
				ajaxLoader.abort();
			}

			tmp.empty();
		},

		fancybox_error = function() {
			$.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {
				'scrolling'		: 'no',
				'padding'		: 20,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'
			});
		},

		fancybox_get_viewport = function() {
			return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
		},

		fancybox_get_zoom_to = function () {
			var view	= fancybox_get_viewport(),
				to		= {},

				margin = currentOpts.margin,
				resize = currentOpts.autoScale,

				horizontal_space	= (shadow + margin) * 2,
				vertical_space		= (shadow + margin) * 2,
				double_padding		= (currentOpts.padding * 2),

				ratio;

			if (currentOpts.width.toString().indexOf('%') > -1) {
				to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ;
				resize = false;

			} else {
				to.width = currentOpts.width + double_padding;
			}

			if (currentOpts.height.toString().indexOf('%') > -1) {
				to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2);
				resize = false;

			} else {
				to.height = currentOpts.height + double_padding;
			}

			if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) {
				if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
					horizontal_space	+= double_padding;
					vertical_space		+= double_padding;

					ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height);

					to.width	= Math.round(ratio * (to.width	- double_padding)) + double_padding;
					to.height	= Math.round(ratio * (to.height	- double_padding)) + double_padding;

				} else {
					to.width	= Math.min(to.width,	(view[0] - horizontal_space));
					to.height	= Math.min(to.height,	(view[1] - vertical_space));
				}
			}

			to.top	= view[3] + ((view[1] - (to.height	+ (shadow * 2 ))) * 0.5);
			to.left	= view[2] + ((view[0] - (to.width	+ (shadow * 2 ))) * 0.5);

			if (currentOpts.autoScale === false) {
				to.top	= Math.max(view[3] + margin, to.top);
				to.left	= Math.max(view[2] + margin, to.left);
			}

			return to;
		},

		fancybox_format_title = function(title) {
			if (title && title.length) {
				switch (currentOpts.titlePosition) {
					case 'inside':
						return title;
					case 'over':
						return '<span id="fancybox-title-over">' + title + '</span>';
					default:
						return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">' + title + '</span><span id="fancybox-title-right"></span></span>';
				}
			}

			return false;
		},

		fancybox_process_title = function() {
			var title	= currentOpts.title,
				width	= final_pos.width - (currentOpts.padding * 2),
				titlec	= 'fancybox-title-' + currentOpts.titlePosition;

			$('#fancybox-title').remove();

			titleh = 0;

			if (currentOpts.titleShow === false) {
				return;
			}

			title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title);

			if (!title || title === '') {
				return;
			}

			$('<div id="fancybox-title" class="' + titlec + '" />').css({
				'width'			: width,
				'paddingLeft'	: currentOpts.padding,
				'paddingRight'	: currentOpts.padding
			}).html(title).appendTo('body');

			switch (currentOpts.titlePosition) {
				case 'inside':
					titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding;
					final_pos.height += titleh;
				break;

				case 'over':
					$('#fancybox-title').css('bottom', currentOpts.padding);
				break;

				default:
					$('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1);
				break;
			}

			$('#fancybox-title').appendTo( outer ).hide();
		},

		fancybox_set_navigation = function() {
			$(document).unbind('keydown.fb').bind('keydown.fb', function(e) {
				if (e.keyCode == 27 && currentOpts.enableEscapeButton) {
					e.preventDefault();
					$.fancybox.close();

				} else if (e.keyCode == 37) {
					e.preventDefault();
					$.fancybox.prev();

				} else if (e.keyCode == 39) {
					e.preventDefault();
					$.fancybox.next();
				}
			});

			if ($.fn.mousewheel) {
				wrap.unbind('mousewheel.fb');

				if (currentArray.length > 1) {
					wrap.bind('mousewheel.fb', function(e, delta) {
						e.preventDefault();

						if (busy || delta === 0) {
							return;
						}

						if (delta > 0) {
							$.fancybox.prev();
						} else {
							$.fancybox.next();
						}
					});
				}
			}

			if (!currentOpts.showNavArrows) { return; }

			if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) {
				nav_left.show();
			}

			if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) {
				nav_right.show();
			}
		},

		fancybox_preload_images = function() {
			var href,
				objNext;

			if ((currentArray.length -1) > currentIndex) {
				href = currentArray[ currentIndex + 1 ].href;

				if (typeof href !== 'undefined' && href.match(imgRegExp)) {
					objNext = new Image();
					objNext.src = href;
				}
			}

			if (currentIndex > 0) {
				href = currentArray[ currentIndex - 1 ].href;

				if (typeof href !== 'undefined' && href.match(imgRegExp)) {
					objNext = new Image();
					objNext.src = href;
				}
			}
		},

		_finish = function () {
			inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible')));

			if (!$.support.opacity) {
				inner.get(0).style.removeAttribute('filter');
				wrap.get(0).style.removeAttribute('filter');
			}

			$('#fancybox-title').show();

			if (currentOpts.hideOnContentClick)	{
				inner.one('click', $.fancybox.close);
			}
			if (currentOpts.hideOnOverlayClick)	{
				overlay.one('click', $.fancybox.close);
			}

			if (currentOpts.showCloseButton) {
				close.show();
			}

			fancybox_set_navigation();

			$(window).bind("resize.fb", $.fancybox.center);

			if (currentOpts.centerOnScroll) {
				$(window).bind("scroll.fb", $.fancybox.center);
			} else {
				$(window).unbind("scroll.fb");
			}

			if ($.isFunction(currentOpts.onComplete)) {
				currentOpts.onComplete(currentArray, currentIndex, currentOpts);
			}

			busy = false;

			fancybox_preload_images();
		},

		fancybox_draw = function(pos) {
			var width	= Math.round(start_pos.width	+ (final_pos.width	- start_pos.width)	* pos),
				height	= Math.round(start_pos.height	+ (final_pos.height	- start_pos.height)	* pos),

				top		= Math.round(start_pos.top	+ (final_pos.top	- start_pos.top)	* pos),
				left	= Math.round(start_pos.left	+ (final_pos.left	- start_pos.left)	* pos);

			wrap.css({
				'width'		: width		+ 'px',
				'height'	: height	+ 'px',
				'top'		: top		+ 'px',
				'left'		: left		+ 'px'
			});

			width	= Math.max(width - currentOpts.padding * 2, 0);
			height	= Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0);

			inner.css({
				'width'		: width		+ 'px',
				'height'	: height	+ 'px'
			});

			if (typeof final_pos.opacity !== 'undefined') {
				wrap.css('opacity', (pos < 0.5 ? 0.5 : pos));
			}
		},

		fancybox_get_obj_pos = function(obj) {
			var pos		= obj.offset();

			pos.top		+= parseFloat( obj.css('paddingTop') )	|| 0;
			pos.left	+= parseFloat( obj.css('paddingLeft') )	|| 0;

			pos.top		+= parseFloat( obj.css('border-top-width') )	|| 0;
			pos.left	+= parseFloat( obj.css('border-left-width') )	|| 0;

			pos.width	= obj.width();
			pos.height	= obj.height();

			return pos;
		},

		fancybox_get_zoom_from = function() {
			var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
				from = {},
				pos,
				view;

			if (orig && orig.length) {
				pos = fancybox_get_obj_pos(orig);

				from = {
					width	: (pos.width	+ (currentOpts.padding * 2)),
					height	: (pos.height	+ (currentOpts.padding * 2)),
					top		: (pos.top		- currentOpts.padding - shadow),
					left	: (pos.left		- currentOpts.padding - shadow)
				};

			} else {
				view = fancybox_get_viewport();

				from = {
					width	: 1,
					height	: 1,
					top		: view[3] + view[1] * 0.5,
					left	: view[2] + view[0] * 0.5
				};
			}

			return from;
		},

		fancybox_show = function() {
			loading.hide();

			if (wrap.is(":visible") && $.isFunction(currentOpts.onCleanup)) {
				if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
					$.event.trigger('fancybox-cancel');

					busy = false;
					return;
				}
			}

			currentArray	= selectedArray;
			currentIndex	= selectedIndex;
			currentOpts		= selectedOpts;

			inner.get(0).scrollTop	= 0;
			inner.get(0).scrollLeft	= 0;

			if (currentOpts.overlayShow) {
				if (isIE6) {
					$('select:not(#fancybox-tmp select)').filter(function() {
						return this.style.visibility !== 'hidden';
					}).css({'visibility':'hidden'}).one('fancybox-cleanup', function() {
						this.style.visibility = 'inherit';
					});
				}

				overlay.css({
					'background-color'	: currentOpts.overlayColor,
					'opacity'			: currentOpts.overlayOpacity
				}).unbind().show();
			}

			final_pos = fancybox_get_zoom_to();

			fancybox_process_title();

			if (wrap.is(":visible")) {
				$( close.add( nav_left ).add( nav_right ) ).hide();

				var pos = wrap.position(),
					equal;

				start_pos = {
					top		:	pos.top ,
					left	:	pos.left,
					width	:	wrap.width(),
					height	:	wrap.height()
				};

				equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);

				inner.fadeOut(currentOpts.changeFade, function() {
					var finish_resizing = function() {
						inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish);
					};

					$.event.trigger('fancybox-change');

					inner.empty().css('overflow', 'hidden');

					if (equal) {
						inner.css({
							top			: currentOpts.padding,
							left		: currentOpts.padding,
							width		: Math.max(final_pos.width	- (currentOpts.padding * 2), 1),
							height		: Math.max(final_pos.height	- (currentOpts.padding * 2) - titleh, 1)
						});

						finish_resizing();

					} else {
						inner.css({
							top			: currentOpts.padding,
							left		: currentOpts.padding,
							width		: Math.max(start_pos.width	- (currentOpts.padding * 2), 1),
							height		: Math.max(start_pos.height	- (currentOpts.padding * 2), 1)
						});

						fx.prop = 0;

						$(fx).animate({ prop: 1 }, {
							 duration	: currentOpts.changeSpeed,
							 easing		: currentOpts.easingChange,
							 step		: fancybox_draw,
							 complete	: finish_resizing
						});
					}
				});

				return;
			}

			wrap.css('opacity', 1);

			if (currentOpts.transitionIn == 'elastic') {
				start_pos = fancybox_get_zoom_from();

				inner.css({
						top			: currentOpts.padding,
						left		: currentOpts.padding,
						width		: Math.max(start_pos.width	- (currentOpts.padding * 2), 1),
						height		: Math.max(start_pos.height	- (currentOpts.padding * 2), 1)
					})
					.html( tmp.contents() );

				wrap.css(start_pos).show();

				if (currentOpts.opacity) {
					final_pos.opacity = 0;
				}

				fx.prop = 0;

				$(fx).animate({ prop: 1 }, {
					 duration	: currentOpts.speedIn,
					 easing		: currentOpts.easingIn,
					 step		: fancybox_draw,
					 complete	: _finish
				});

			} else {
				inner.css({
						top			: currentOpts.padding,
						left		: currentOpts.padding,
						width		: Math.max(final_pos.width	- (currentOpts.padding * 2), 1),
						height		: Math.max(final_pos.height	- (currentOpts.padding * 2) - titleh, 1)
					})
					.html( tmp.contents() );

				wrap.css( final_pos ).fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
			}
		},

		fancybox_process_inline = function() {
			tmp.width(	selectedOpts.width );
			tmp.height(	selectedOpts.height );

			if (selectedOpts.width	== 'auto') {
				selectedOpts.width = tmp.width();
			}
			if (selectedOpts.height	== 'auto') {
				selectedOpts.height	= tmp.height();
			}

			fancybox_show();
		},

		fancybox_process_image = function() {
			busy = true;

			selectedOpts.width	= imgPreloader.width;
			selectedOpts.height	= imgPreloader.height;

			$("<img />").attr({
				'id'	: 'fancybox-img',
				'src'	: imgPreloader.src,
				'alt'	: selectedOpts.title
			}).appendTo( tmp );

			fancybox_show();
		},

		fancybox_start = function() {
			fancybox_abort();

			var obj	= selectedArray[ selectedIndex ],
				href,
				type,
				title,
				str,
				emb,
				selector,
				data;

			selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
			title = obj.title || $(obj).title || selectedOpts.title || '';

			if (obj.nodeName && !selectedOpts.orig) {
				selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
			}

			if (title === '' && selectedOpts.orig) {
				title = selectedOpts.orig.attr('alt');
			}

			if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) {
				href = selectedOpts.href || null;
			} else {
				href = selectedOpts.href || obj.href || null;
			}

			if (selectedOpts.type) {
				type = selectedOpts.type;

				if (!href) {
					href = selectedOpts.content;
				}

			} else if (selectedOpts.content) {
				type	= 'html';

			} else if (href) {
				if (href.match(imgRegExp)) {
					type = 'image';

				} else if (href.match(swfRegExp)) {
					type = 'swf';

				} else if ($(obj).hasClass("iframe")) {
					type = 'iframe';

				} else if (href.match(/#/)) {
					obj = href.substr(href.indexOf("#"));

					type = $(obj).length > 0 ? 'inline' : 'ajax';
				} else {
					type = 'ajax';
				}
			} else {
				type = 'inline';
			}

			selectedOpts.type	= type;
			selectedOpts.href	= href;
			selectedOpts.title	= title;

			if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') {
				selectedOpts.width		= 'auto';
				selectedOpts.height		= 'auto';
			}

			if (selectedOpts.modal) {
				selectedOpts.overlayShow		= true;
				selectedOpts.hideOnOverlayClick	= false;
				selectedOpts.hideOnContentClick	= false;
				selectedOpts.enableEscapeButton	= false;
				selectedOpts.showCloseButton	= false;
			}

			if ($.isFunction(selectedOpts.onStart)) {
				if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) {
					busy = false;
					return;
				}
			}

			tmp.css('padding', (shadow + selectedOpts.padding + selectedOpts.margin));

			$('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
				$(this).replaceWith(inner.children());
			});

			switch (type) {
				case 'html' :
					tmp.html( selectedOpts.content );
					fancybox_process_inline();
				break;

				case 'inline' :
					$('<div class="fancybox-inline-tmp" />').hide().insertBefore( $(obj) ).bind('fancybox-cleanup', function() {
						$(this).replaceWith(inner.children());
					}).bind('fancybox-cancel', function() {
						$(this).replaceWith(tmp.children());
					});

					$(obj).appendTo(tmp);

					fancybox_process_inline();
				break;

				case 'image':
					busy = false;

					$.fancybox.showActivity();

					imgPreloader = new Image();

					imgPreloader.onerror = function() {
						fancybox_error();
					};

					imgPreloader.onload = function() {
						imgPreloader.onerror = null;
						imgPreloader.onload = null;
						fancybox_process_image();
					};

					imgPreloader.src = href;

				break;

				case 'swf':
					str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
					emb = '';

					$.each(selectedOpts.swf, function(name, val) {
						str += '<param name="' + name + '" value="' + val + '"></param>';
						emb += ' ' + name + '="' + val + '"';
					});

					str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';

					tmp.html(str);

					fancybox_process_inline();
				break;

				case 'ajax':
					selector	= href.split('#', 2);
					data		= selectedOpts.ajax.data || {};

					if (selector.length > 1) {
						href = selector[0];

						if (typeof data == "string") {
							data += '&selector=' + selector[1];
						} else {
							data.selector = selector[1];
						}
					}

					busy = false;
					$.fancybox.showActivity();

					ajaxLoader = $.ajax($.extend(selectedOpts.ajax, {
						url		: href,
						data	: data,
						error	: fancybox_error,
						success : function(data, textStatus, XMLHttpRequest) {
							if (ajaxLoader.status == 200) {
								tmp.html( data );
								fancybox_process_inline();
							}
						}
					}));

				break;

				case 'iframe' :
					$('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + selectedOpts.scrolling + '" src="' + selectedOpts.href + '"></iframe>').appendTo(tmp);
					fancybox_show();
				break;
			}
		},

		fancybox_animate_loading = function() {
			if (!loading.is(':visible')){
				clearInterval(loadingTimer);
				return;
			}

			$('div', loading).css('top', (loadingFrame * -40) + 'px');

			loadingFrame = (loadingFrame + 1) % 12;
		},

		fancybox_init = function() {
			if ($("#fancybox-wrap").length) {
				return;
			}

			$('body').append(
				tmp			= $('<div id="fancybox-tmp"></div>'),
				loading		= $('<div id="fancybox-loading"><div></div></div>'),
				overlay		= $('<div id="fancybox-overlay"></div>'),
				wrap		= $('<div id="fancybox-wrap"></div>')
			);

			if (!$.support.opacity) {
				wrap.addClass('fancybox-ie');
				loading.addClass('fancybox-ie');
			}

			outer = $('<div id="fancybox-outer"></div>')
				.append('<div class="fancy-bg" id="fancy-bg-n"></div><div class="fancy-bg" id="fancy-bg-ne"></div><div class="fancy-bg" id="fancy-bg-e"></div><div class="fancy-bg" id="fancy-bg-se"></div><div class="fancy-bg" id="fancy-bg-s"></div><div class="fancy-bg" id="fancy-bg-sw"></div><div class="fancy-bg" id="fancy-bg-w"></div><div class="fancy-bg" id="fancy-bg-nw"></div>')
				.appendTo( wrap );

			outer.append(
				inner		= $('<div id="fancybox-inner"></div>'),
				close		= $('<a id="fancybox-close"></a>'),

				nav_left	= $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
				nav_right	= $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
			);

			close.click($.fancybox.close);
			loading.click($.fancybox.cancel);

			nav_left.click(function(e) {
				e.preventDefault();
				$.fancybox.prev();
			});

			nav_right.click(function(e) {
				e.preventDefault();
				$.fancybox.next();
			});

			if (isIE6) {
				overlay.get(0).style.setExpression('height',	"document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");
				loading.get(0).style.setExpression('top',		"(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");

				outer.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>');
			}
		};

	/*
	 * Public methods
	 */

	$.fn.fancybox = function(options) {
		$(this)
			.data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
			.unbind('click.fb').bind('click.fb', function(e) {
				e.preventDefault();

				if (busy) {
					return;
				}

				busy = true;

				$(this).blur();

				selectedArray	= [];
				selectedIndex	= 0;

				var rel = $(this).attr('rel') || '';

				if (!rel || rel == '' || rel === 'nofollow') {
					selectedArray.push(this);

				} else {
					selectedArray	= $("a[rel=" + rel + "], area[rel=" + rel + "]");
					selectedIndex	= selectedArray.index( this );
				}

				fancybox_start();

				return false;
			});

		return this;
	};

	$.fancybox = function(obj) {
		if (busy) {
			return;
		}

		busy = true;

		var opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};

		selectedArray	= [];
		selectedIndex	= opts.index || 0;

		if ($.isArray(obj)) {
			for (var i = 0, j = obj.length; i < j; i++) {
				if (typeof obj[i] == 'object') {
					$(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
				} else {
					obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));
				}
			}

			selectedArray = jQuery.merge(selectedArray, obj);

		} else {
			if (typeof obj == 'object') {
				$(obj).data('fancybox', $.extend({}, opts, obj));
			} else {
				obj = $({}).data('fancybox', $.extend({content : obj}, opts));
			}

			selectedArray.push(obj);
		}

		if (selectedIndex > selectedArray.length || selectedIndex < 0) {
			selectedIndex = 0;
		}

		fancybox_start();
	};

	$.fancybox.showActivity = function() {
		clearInterval(loadingTimer);

		loading.show();
		loadingTimer = setInterval(fancybox_animate_loading, 66);
	};

	$.fancybox.hideActivity = function() {
		loading.hide();
	};

	$.fancybox.next = function() {
		return $.fancybox.pos( currentIndex + 1);
	};

	$.fancybox.prev = function() {
		return $.fancybox.pos( currentIndex - 1);
	};

	$.fancybox.pos = function(pos) {
		if (busy) {
			return;
		}

		pos = parseInt(pos, 10);

		if (pos > -1 && currentArray.length > pos) {
			selectedIndex = pos;
			fancybox_start();
		}

		if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) {
			selectedIndex = currentArray.length - 1;
			fancybox_start();
		}

		if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) {
			selectedIndex = 0;
			fancybox_start();
		}

		return;
	};

	$.fancybox.cancel = function() {
		if (busy) {
			return;
		}

		busy = true;

		$.event.trigger('fancybox-cancel');

		fancybox_abort();

		if (selectedOpts && $.isFunction(selectedOpts.onCancel)) {
			selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
		}

		busy = false;
	};

	// Note: within an iframe use - parent.$.fancybox.close();
	$.fancybox.close = function() {
		if (busy || wrap.is(':hidden')) {
			return;
		}

		busy = true;

		if (currentOpts && $.isFunction(currentOpts.onCleanup)) {
			if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
				busy = false;
				return;
			}
		}

		fancybox_abort();

		$(close.add( nav_left ).add( nav_right )).hide();

		$('#fancybox-title').remove();

		wrap.add(inner).add(overlay).unbind();

		$(window).unbind("resize.fb scroll.fb");
		$(document).unbind('keydown.fb');

		function _cleanup() {
			overlay.fadeOut('fast');

			wrap.hide();

			$.event.trigger('fancybox-cleanup');

			inner.empty();

			if ($.isFunction(currentOpts.onClosed)) {
				currentOpts.onClosed(currentArray, currentIndex, currentOpts);
			}

			currentArray	= selectedOpts	= [];
			currentIndex	= selectedIndex	= 0;
			currentOpts		= selectedOpts	= {};

			busy = false;
		}

		inner.css('overflow', 'hidden');

		if (currentOpts.transitionOut == 'elastic') {
			start_pos = fancybox_get_zoom_from();

			var pos = wrap.position();

			final_pos = {
				top		:	pos.top ,
				left	:	pos.left,
				width	:	wrap.width(),
				height	:	wrap.height()
			};

			if (currentOpts.opacity) {
				final_pos.opacity = 1;
			}

			fx.prop = 1;

			$(fx).animate({ prop: 0 }, {
				 duration	: currentOpts.speedOut,
				 easing		: currentOpts.easingOut,
				 step		: fancybox_draw,
				 complete	: _cleanup
			});

		} else {
			wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
		}
	};

	$.fancybox.resize = function() {
		var c, h;

		if (busy || wrap.is(':hidden')) {
			return;
		}

		busy = true;

		c = inner.wrapInner("<div style='overflow:auto'></div>").children();
		h = c.height();

		wrap.css({height:	h + (currentOpts.padding * 2) + titleh});
		inner.css({height:	h});

		c.replaceWith(c.children());

		$.fancybox.center();
	};

	$.fancybox.center = function() {
		busy = true;

		var view	= fancybox_get_viewport(),
			margin	= currentOpts.margin,
			to		= {};

		to.top	= view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5);
		to.left	= view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5);

		to.top	= Math.max(view[3] + margin, to.top);
		to.left	= Math.max(view[2] + margin, to.left);

		wrap.css(to);

		busy = false;
	};

	$.fn.fancybox.defaults = {
		padding				:	0,
		margin				:	0,
		opacity				:	false,
		modal				:	false,
		cyclic				:	false,
		scrolling			:	'no',	// 'auto', 'yes' or 'no'

		width				:	400,
		height				:	340,

		autoScale			:	true,
		autoDimensions		:	true,
		centerOnScroll		:	false,

		ajax				:	{},
		swf					:	{ wmode: 'transparent' },

		hideOnOverlayClick	:	true,
		hideOnContentClick	:	false,

		overlayShow			:	true,
		overlayOpacity		:	0.8,
		overlayColor		:	'#000',

		titleShow			:	true,
		titlePosition		:	'outside',	// 'outside', 'inside' or 'over'
		titleFormat			:	null,

		transitionIn		:	'elastic',	// 'elastic', 'fade' or 'none'
		transitionOut		:	'fade',	// 'elastic', 'fade' or 'none'

		speedIn				:	300,
		speedOut			:	300,

		changeSpeed			:	300,
		changeFade			:	'fast',

		easingIn			:	'swing',
		easingOut			:	'swing',

		showCloseButton		:	true,
		showNavArrows		:	true,
		enableEscapeButton	:	true,

		onStart				:	null,
		onCancel			:	null,
		onComplete			:	null,
		onCleanup			:	null,
		onClosed			:	null
	};

	$(document).ready(function() {
		fancybox_init();
	});

})(jQuery);


/* SLIDER */
function ImageFlow () {
	this.defaults = {
		animationSpeed:     50,
		aspectRatio:        1.964,
		buttons:            true,
		captions:           true,
		circular:           true,
		imageCursor:        'default',
		ImageFlowID:        'imageflow',
		imageFocusM:        1.0,
		imageFocusMax:      4,
		imagePath:          '',
		imageScaling:       true,
		imagesHeight:       0.67,
		imagesM:            1.0,
		onClick:            function() { document.location = this.url; },
		opacity:            false,
		opacityArray:       [10,8,6,4,2],
		percentLandscape:   100,
		percentOther:       100,
		preloadImages:      true,
		reflections:        false,
		reflectionGET:      '',
		reflectionP:        0.5,
		reflectionPNG:      false,
		reflectPath:        '',
		scrollbarP:         0.9,
		slider:             true,
		sliderCursor:       'cursor',
		sliderWidth:        14,
		slideshow:          false,
		slideshowSpeed:     1500,
		slideshowAutoplay:  false,
		startID:            1,
		glideToStartID:     true,
		startAnimation:     false,
		xStep:              150
	};


	var my = this;

	this.init = function (options)	{
		for(var name in my.defaults) {
			this[name] = (options !== undefined && options[name] !== undefined) ? options[name] : my.defaults[name];
		}


		var ImageFlowDiv = document.getElementById(my.ImageFlowID);
		if ( ImageFlowDiv ) {

			ImageFlowDiv.style.visibility = 'visible';
			this.ImageFlowDiv = ImageFlowDiv;


			if ( this.createStructure() ) {
				this.imagesDiv = document.getElementById(my.ImageFlowID+'_images');
				this.captionDiv = document.getElementById(my.ImageFlowID+'_caption');
				this.navigationDiv = document.getElementById(my.ImageFlowID+'_navigation');
				this.scrollbarDiv = document.getElementById(my.ImageFlowID+'_scrollbar');
				this.sliderDiv = document.getElementById(my.ImageFlowID+'_slider');
				this.buttonNextDiv = document.getElementById(my.ImageFlowID+'_next');
				this.buttonPreviousDiv = document.getElementById(my.ImageFlowID+'_previous');
				this.buttonSlideshow = document.getElementById(my.ImageFlowID+'_slideshow');

				this.indexArray = [];
				this.current = 0;
				this.imageID = 0;
				this.target = 0;
				this.memTarget = 0;
				this.firstRefresh = true;
				this.firstCheck = true;
				this.busy = false;


				var width = this.ImageFlowDiv.offsetWidth;
				var height = Math.round(width / my.aspectRatio);
				document.getElementById(my.ImageFlowID+'_loading_txt').style.paddingTop = ((height * 0.5) -22) + 'px';
				ImageFlowDiv.style.height = height + 'px';


				this.loadingProgress();
			}
		}
	};

	this.createStructure = function() {

		var imagesDiv = my.Helper.createDocumentElement('div','images');
		var node, version, src, imageNode;
		var max = my.ImageFlowDiv.childNodes.length;
		for(var index = 0; index < max; index++) {
			node = my.ImageFlowDiv.childNodes[index];
			if (node && node.nodeType == 1 && node.nodeName == 'IMG') {

				if(my.reflections === true) {
					version = (my.reflectionPNG) ? '3' : '2';
					src = my.imagePath+node.getAttribute('src',2);
					src = my.reflectPath+'reflect'+version+'.php?img='+src+my.reflectionGET;
					node.setAttribute('src',src);
				}

				imageNode = node.cloneNode(true);
				imagesDiv.appendChild(imageNode);
			}
		}

		if(my.circular)	{
			var first = my.Helper.createDocumentElement('div','images');
			var last = my.Helper.createDocumentElement('div','images');

			max = imagesDiv.childNodes.length;
			if(max < my.imageFocusMax) {
				my.imageFocusMax = max;
			}

			if(max > 1) {

				var i;
				for(i = 0; i < max; i++) {
					node = imagesDiv.childNodes[i];
					if(i < my.imageFocusMax) {
						imageNode = node.cloneNode(true);
						first.appendChild(imageNode);
					}
					if(max-i < my.imageFocusMax+1) {
						imageNode = node.cloneNode(true);
						last.appendChild(imageNode);
					}
				}

				for(i = 0; i < max; i++) {
					node = imagesDiv.childNodes[i];
					imageNode = node.cloneNode(true);
					last.appendChild(imageNode);
				}
				for(i = 0; i < my.imageFocusMax; i++) {
					node = first.childNodes[i];
					imageNode = node.cloneNode(true);
					last.appendChild(imageNode);
				}
				imagesDiv = last;
			}
		}


		if(my.slideshow) {
			var slideshowButton = my.Helper.createDocumentElement('div','slideshow');
			imagesDiv.appendChild(slideshowButton);
		}

		var loadingP = my.Helper.createDocumentElement('p','loading_txt');
		var loadingText = document.createTextNode(' ');
		loadingP.appendChild(loadingText);

		var loadingDiv = my.Helper.createDocumentElement('div','loading');

		var loadingBarDiv = my.Helper.createDocumentElement('div','loading_bar');
		loadingDiv.appendChild(loadingBarDiv);

		var captionDiv = my.Helper.createDocumentElement('div','caption');

		var scrollbarDiv = my.Helper.createDocumentElement('div','scrollbar');
		var sliderDiv = my.Helper.createDocumentElement('div','slider');
		scrollbarDiv.appendChild(sliderDiv);
		if(my.buttons)	{
			var buttonPreviousDiv = my.Helper.createDocumentElement('div','previous', 'button');
			var buttonNextDiv = my.Helper.createDocumentElement('div','next', 'button');
			scrollbarDiv.appendChild(buttonPreviousDiv);
			scrollbarDiv.appendChild(buttonNextDiv);
		}

		var navigationDiv = my.Helper.createDocumentElement('div','navigation');
		navigationDiv.appendChild(captionDiv);
		navigationDiv.appendChild(scrollbarDiv);

		var success = false;
		if (my.ImageFlowDiv.appendChild(imagesDiv) && my.ImageFlowDiv.appendChild(loadingP) && my.ImageFlowDiv.appendChild(loadingDiv) && my.ImageFlowDiv.appendChild(navigationDiv)) {
			max = my.ImageFlowDiv.childNodes.length;
			for(index = 0; index < max; index++) {
				node = my.ImageFlowDiv.childNodes[index];
				if (node && node.nodeType == 1 && node.nodeName == 'IMG') {
					my.ImageFlowDiv.removeChild(node);
				}
			}
			success = true;
		}
		return success;
	};

	this.loadingProgress = function() {
		var p = my.loadingStatus();
		if((p < 100 || my.firstCheck) && my.preloadImages) {
			if(my.firstCheck && p == 100) {
				my.firstCheck = false;
				window.setTimeout(my.loadingProgress, 100);
			}
			else {
				window.setTimeout(my.loadingProgress, 40);
			}
		}
		else {
			document.getElementById(my.ImageFlowID+'_loading_txt').style.display = 'none';
			document.getElementById(my.ImageFlowID+'_loading').style.display = 'none';
			window.setTimeout(my.Helper.addResizeEvent, 1000);
			my.refresh();
			if(my.max > 1) {
				my.MouseWheel.init();
				my.MouseDrag.init();
				my.Touch.init();
				my.Key.init();

				if(my.slideshow) {
					my.Slideshow.init();
				}
				if(my.slider) {
					my.scrollbarDiv.style.visibility = 'visible';
				}
			}
		}
	};

	this.loadingStatus = function() {
		var max = my.imagesDiv.childNodes.length;
		var i = 0, completed = 0;
		var image = null;
		for(var index = 0; index < max; index++) {
			image = my.imagesDiv.childNodes[index];
			if(image && image.nodeType == 1 && image.nodeName == 'IMG') {
				if(image.complete) {
					completed++;
				}
				i++;
			}
		}

		var finished = Math.round((completed/i)*100);
		var loadingBar = document.getElementById(my.ImageFlowID+'_loading_bar');
		loadingBar.style.width = finished+'%';

		if(my.circular) {
			i = i - (my.imageFocusMax*2);
			completed = (finished < 1) ? 0 : Math.round((i/100)*finished);
		}
		var loadingP = document.getElementById(my.ImageFlowID+'_loading_txt');
		var loadingTxt = document.createTextNode('loading images '+completed+'/'+i);
		loadingP.replaceChild(loadingTxt,loadingP.firstChild);
		return finished;
	};

	this.refresh = function() {
		this.imagesDivWidth = my.imagesDiv.offsetWidth+my.imagesDiv.offsetLeft;
		this.maxHeight = Math.round(my.imagesDivWidth / my.aspectRatio);
		this.maxHeight = 200;
		this.maxFocus = my.imageFocusMax * my.xStep;
		this.size = my.imagesDivWidth * 0.5;
		this.sliderWidth = my.sliderWidth * 0.5;
		this.scrollbarWidth = (my.imagesDivWidth - ( Math.round(my.sliderWidth) * 2)) * my.scrollbarP;
		this.imagesDivHeight = Math.round(my.maxHeight * my.imagesHeight);

		my.ImageFlowDiv.style.height = my.maxHeight + 'px';
		my.imagesDiv.style.height =  my.imagesDivHeight + 'px';
		my.navigationDiv.style.height =  (my.maxHeight - my.imagesDivHeight) + 'px';
		my.captionDiv.style.width = my.imagesDivWidth + 'px';
		my.captionDiv.style.width = 200 + 'px';
		my.captionDiv.style.paddingTop = Math.round(my.imagesDivWidth * 0.02) + 'px';
		my.scrollbarDiv.style.width = my.scrollbarWidth + 'px';
		my.scrollbarDiv.style.marginTop = Math.round(my.imagesDivWidth * 0.02) + 'px';
		my.scrollbarDiv.style.marginLeft = Math.round(my.sliderWidth + ((my.imagesDivWidth - my.scrollbarWidth)/2)) + 'px';
		my.sliderDiv.style.cursor = my.sliderCursor;
		my.sliderDiv.onmousedown = function () { my.MouseDrag.start(this); return false;};

		if(my.buttons) {
			my.buttonPreviousDiv.onclick = function () { my.MouseWheel.handle(1); };
			my.buttonNextDiv.onclick = function () { my.MouseWheel.handle(-1); };
		}

		var multi = (my.reflections === true) ? my.reflectionP + 1 : 1;
		var max = my.imagesDiv.childNodes.length;
		var i = 0;
		var image = null;
		for (var index = 0; index < max; index++) {
			image = my.imagesDiv.childNodes[index];
			if(image !== null && image.nodeType == 1 && image.nodeName == 'IMG') {
				this.indexArray[i] = index;
				image.url = image.getAttribute('longdesc');
				image.xPosition = (-i * my.xStep);
				image.i = i;

				if(my.firstRefresh) {
					if(image.getAttribute('width') !== null && image.getAttribute('height') !== null) {
						image.w = image.getAttribute('width');
						image.h = image.getAttribute('height') * multi;
					}
					else{
						image.w = image.width;
						image.h = image.height;
					}
				}

				if((image.w) > (image.h / (my.reflectionP + 1))) {
					image.pc = my.percentLandscape;
					image.pcMem = my.percentLandscape;
				}
				else {
					image.pc = my.percentOther;
					image.pcMem = my.percentOther;
				}

				if(my.imageScaling === false) {
					image.style.position = 'relative';
					image.style.display = 'inline';
				}

				image.style.cursor = my.imageCursor;
				i++;
			}
		}
		this.max = my.indexArray.length;

		if(my.imageScaling === false) {
			image = my.imagesDiv.childNodes[my.indexArray[0]];

			this.totalImagesWidth = image.w * my.max;
			image.style.paddingLeft = (my.imagesDivWidth/2) + (image.w/2) + 'px';

			my.imagesDiv.style.height =  image.h + 'px';
			my.navigationDiv.style.height =  (my.maxHeight - image.h) + 'px';
		}


		if(my.firstRefresh) {
			my.firstRefresh = false;
			my.imageID = my.startID-1;
			if (my.imageID < 0 ) {
				my.imageID = 0;
			}

			if(my.circular) {
				my.imageID = my.imageID + my.imageFocusMax;
			}

			maxId = (my.circular) ?  (my.max-(my.imageFocusMax))-1 : my.max-1;
			if (my.imageID > maxId) {
				my.imageID = maxId;
			}

			if(my.glideToStartID === false) {
				my.moveTo(-my.imageID * my.xStep);
			}

			if(my.startAnimation) {
				my.moveTo(5000);
			}
		}

		if(my.max > 1) {
			my.glideTo(my.imageID);
		}

		my.moveTo(my.current);
	};

	this.moveTo = function(x) {
		this.current = x;
		this.zIndex = my.max;
		for (var index = 0; index < my.max; index++) {
			var image = my.imagesDiv.childNodes[my.indexArray[index]];
			var currentImage = index * -my.xStep;
			if(my.imageScaling) {
				if ((currentImage + my.maxFocus) < my.memTarget || (currentImage - my.maxFocus) > my.memTarget) {
					image.style.visibility = 'hidden';
					image.style.display = 'none';
				}
				else {
					var z = (Math.sqrt(10000 + x * x) + 100) * my.imagesM;
					var xs = x / z * my.size + my.size;

					image.style.display = 'block';
					var newImageH = (image.h / image.w * image.pc) / z * my.size;
					var newImageW = 0;
					switch (newImageH > my.maxHeight) {
						case false:
							newImageW = image.pc / z * my.size;
							break;

						default:
							newImageH = my.maxHeight;
							newImageW = image.w * newImageH / image.h;
							break;
					}

					var newImageTop = (my.imagesDivHeight - newImageH) + ((newImageH / (my.reflectionP + 1)) * my.reflectionP);
					newImageTop = newImageTop-10;
					image.style.left = xs - (image.pc / 2) / z * my.size + 'px';
					if(newImageW && newImageH) {
						image.style.height = newImageH + 'px';
						image.style.width = newImageW + 'px';
						image.style.top = newImageTop + 'px';
					}
					image.style.visibility = 'visible';

					switch ( x < 0 ) {
						case true:
							this.zIndex++;
							break;

						default:
							this.zIndex = my.zIndex - 1;
							break;
					}

					switch ( image.i == my.imageID ) {
						case false:
							image.onclick = function() { my.glideTo(this.i);};
							break;

						default:
							this.zIndex = my.zIndex + 1;
							if(image.url !== '')
							{
								image.onclick = my.onClick;
							}
							break;
					}
					image.style.zIndex = my.zIndex;
					image.style.cursor='pointer';
				}
			}
			else {
				if ((currentImage + my.maxFocus) < my.memTarget || (currentImage - my.maxFocus) > my.memTarget)	{
					image.style.visibility = 'hidden';
				}
				else {
					image.style.visibility = 'visible';


					switch ( image.i == my.imageID ) {
						case false:
							image.onclick = function() { my.glideTo(this.i);};
							break;

						default:
							if(image.url !== '') {
								image.onclick = my.onClick;
							}
							break;
					}
				}
				my.imagesDiv.style.marginLeft = (x - my.totalImagesWidth) + 'px';
			}

			x += my.xStep;
		}
	};


	this.glideTo = function(imageID) {
		var jumpTarget, clonedImageID;
		if(my.circular) {
			if(imageID+1 === my.imageFocusMax) {
				clonedImageID = my.max - my.imageFocusMax;
				jumpTarget = -clonedImageID * my.xStep;
				imageID = clonedImageID-1 ;
			}
			if(imageID === (my.max - my.imageFocusMax)) {
				clonedImageID = my.imageFocusMax-1;
				jumpTarget = -clonedImageID * my.xStep;
				imageID = clonedImageID+1;
			}
		}

		var x = -imageID * my.xStep;
		this.target = x;
		this.memTarget = x;
		this.imageID = imageID;
		var caption = my.imagesDiv.childNodes[imageID].getAttribute('alt');
		if (caption === '' || my.captions === false) {
			caption = '&nbsp;';
		}
		my.captionDiv.innerHTML = caption;
		my.captionDiv.style.visibility = 'visible';

		if (my.MouseDrag.busy === false) {
			if(my.circular) {
				this.newSliderX = ((imageID-my.imageFocusMax) * my.scrollbarWidth) / (my.max-(my.imageFocusMax*2)-1) - my.MouseDrag.newX;
			}
			else {
				this.newSliderX = (imageID * my.scrollbarWidth) / (my.max-1) - my.MouseDrag.newX;
			}
			my.sliderDiv.style.marginLeft = (my.newSliderX - my.sliderWidth) + 'px';
		}


		if(my.opacity === true || my.imageFocusM !== my.defaults.imageFocusM) {
			my.Helper.setOpacity(my.imagesDiv.childNodes[imageID], my.opacityArray[0]);
			my.imagesDiv.childNodes[imageID].pc = my.imagesDiv.childNodes[imageID].pc * my.imageFocusM;

			var opacityValue = 0;
			var rightID = 0;
			var leftID = 0;
			var last = my.opacityArray.length;

			for (var i = 1; i < (my.imageFocusMax+1); i++) {
				if((i+1) > last) {
					opacityValue = my.opacityArray[last-1];
				}
				else {
					opacityValue = my.opacityArray[i];
				}

				rightID = imageID + i;
				leftID = imageID - i;

				if (rightID < my.max) {
					my.Helper.setOpacity(my.imagesDiv.childNodes[rightID], opacityValue);
					my.imagesDiv.childNodes[rightID].pc = my.imagesDiv.childNodes[rightID].pcMem;
				}
				if (leftID >= 0) {
					my.Helper.setOpacity(my.imagesDiv.childNodes[leftID], opacityValue);
					my.imagesDiv.childNodes[leftID].pc = my.imagesDiv.childNodes[leftID].pcMem;
				}
			}
		}
		if(jumpTarget) {
			my.moveTo(jumpTarget);
		}

		if (my.busy === false) {
			my.busy = true;
			my.animate();
		}
	};
	this.animate = function() {
		switch (my.target < my.current-1 || my.target > my.current+1) {
			case true:
				my.moveTo(my.current + (my.target-my.current)/3);
				window.setTimeout(my.animate, my.animationSpeed);
				my.busy = true;
				break;

			default:
				my.busy = false;
				break;
		}
	};
	this.glideOnEvent = function(imageID) {

		if(my.slideshow) {
			my.Slideshow.interrupt();
		}

		my.glideTo(imageID);
	};

	this.Slideshow = {
		direction: 1,
		init: function() {
			(my.slideshowAutoplay) ? my.Slideshow.start() : my.Slideshow.stop();
		},
		interrupt: function() {
			my.Helper.removeEvent(my.ImageFlowDiv,'click',my.Slideshow.interrupt);
			my.Slideshow.stop();
		},

		addInterruptEvent: function() {
			my.Helper.addEvent(my.ImageFlowDiv,'click',my.Slideshow.interrupt);
		},

		start: function() {
			my.Helper.setClassName(my.buttonSlideshow, 'slideshow pause');
			my.buttonSlideshow.onclick = function () { my.Slideshow.stop(); };
			my.Slideshow.action = window.setInterval(my.Slideshow.slide, my.slideshowSpeed);
			window.setTimeout(my.Slideshow.addInterruptEvent, 100);
		},

		stop: function() {
			my.Helper.setClassName(my.buttonSlideshow, 'slideshow play');
			my.buttonSlideshow.onclick = function () { my.Slideshow.start(); };
			window.clearInterval(my.Slideshow.action);
		},

		slide: function() {
			var newImageID = my.imageID + my.Slideshow.direction;
			var reverseDirection = false;
			if(newImageID === my.max) {
				my.Slideshow.direction = -1;
				reverseDirection = true;
			}
			if(newImageID < 0) {
				my.Slideshow.direction = 1;
				reverseDirection = true;
			}
			(reverseDirection) ? my.Slideshow.slide() : my.glideTo(newImageID);
		}
	};

	this.MouseWheel = {
		init: function() {
			if(window.addEventListener) 	{
				my.ImageFlowDiv.addEventListener('DOMMouseScroll', my.MouseWheel.get, false);
			}
			my.Helper.addEvent(my.ImageFlowDiv,'mousewheel',my.MouseWheel.get);
		},

		get: function(event) {
			var delta = 0;
			if (!event)	{
				event = window.event;
			}
			if (event.wheelDelta) {
				delta = event.wheelDelta / 120;
			}
			else if (event.detail) {
				delta = -event.detail / 3;
			}
			if (delta) {
				my.MouseWheel.handle(delta);
			}
			my.Helper.suppressBrowserDefault(event);
		},

		handle: function(delta) {
			var change = false;
			var newImageID = 0;
			if(delta > 0) {
				if(my.imageID >= 1) {
					newImageID = my.imageID -1;
					change = true;
				}
			}
			else {
				if(my.imageID < (my.max-1)) 	{
					newImageID = my.imageID +1;
					change = true;
				}
			}
			if(change) {
				my.glideOnEvent(newImageID);
			}
		}
	};

	this.MouseDrag = {
		object: null,
		objectX: 0,
		mouseX: 0,
		newX: 0,
		busy: false,


		init: function() {
			my.Helper.addEvent(my.ImageFlowDiv,'mousemove',my.MouseDrag.drag);
			my.Helper.addEvent(my.ImageFlowDiv,'mouseup',my.MouseDrag.stop);
			my.Helper.addEvent(document,'mouseup',my.MouseDrag.stop);


			my.ImageFlowDiv.onselectstart = function () {
				var selection = true;
				if (my.MouseDrag.busy) {
					selection = false;
				}
				return selection;
			};
		},

		start: function(o) {
			my.MouseDrag.object = o;
			my.MouseDrag.objectX = my.MouseDrag.mouseX - o.offsetLeft + my.newSliderX;
		},

		stop: function() {
			my.MouseDrag.object = null;
			my.MouseDrag.busy = false;
		},

		drag: function(e) {
			var posx = 0;
			if (!e) {
				e = window.event;
			}
			if (e.pageX) {
				posx = e.pageX;
			}
			else if (e.clientX) 	{
				posx = e.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
			}
			my.MouseDrag.mouseX = posx;

			if(my.MouseDrag.object !== null) {
				var newX = (my.MouseDrag.mouseX - my.MouseDrag.objectX) + my.sliderWidth;
				if(newX < ( - my.newSliderX)) {
					newX = - my.newSliderX;
				}
				if(newX > (my.scrollbarWidth - my.newSliderX)) {
					newX = my.scrollbarWidth - my.newSliderX;
				}

				var step, imageID;
				if(my.circular) {
					step = (newX + my.newSliderX) / (my.scrollbarWidth / (my.max-(my.imageFocusMax*2)-1));
					imageID = Math.round(step)+my.imageFocusMax;
				}
				else {
					step = (newX + my.newSliderX) / (my.scrollbarWidth / (my.max-1));
					imageID = Math.round(step);
				}
				my.MouseDrag.newX = newX;
				my.MouseDrag.object.style.left = newX + 'px';
				if(my.imageID !== imageID) {
					my.glideOnEvent(imageID);
				}
				my.MouseDrag.busy = true;
			}
		}
	};

	this.Touch = {
		x: 0,
		startX: 0,
		stopX: 0,
		busy: false,
		first: true,

		init: function() {
			my.Helper.addEvent(my.navigationDiv,'touchstart',my.Touch.start);
			my.Helper.addEvent(document,'touchmove',my.Touch.handle);
			my.Helper.addEvent(document,'touchend',my.Touch.stop);
		},

		isOnNavigationDiv: function(e) {
			var state = false;
			if(e.touches) {
				var target = e.touches[0].target;
				if(target === my.navigationDiv || target === my.sliderDiv || target === my.scrollbarDiv) {
					state = true;
				}
			}
			return state;
		},

		getX: function(e) {
			var x = 0;
			if(e.touches) {
				x = e.touches[0].pageX;
			}
			return x;
		},

		start: function(e) {
			my.Touch.startX = my.Touch.getX(e);
			my.Touch.busy = true;
			my.Helper.suppressBrowserDefault(e);
		},

		isBusy: function() {
			var busy = false;
			if(my.Touch.busy) {
				busy = true;
			}
			return busy;
		},

		handle: function(e) {
			if(my.Touch.isBusy && my.Touch.isOnNavigationDiv(e)) {
				var max = (my.circular) ? (my.max-(my.imageFocusMax*2)-1) : (my.max-1);
				if(my.Touch.first) {
					my.Touch.stopX = (max - my.imageID) * (my.imagesDivWidth / max);
					my.Touch.first = false;
				}
				var newX = -(my.Touch.getX(e) - my.Touch.startX - my.Touch.stopX);

				if(newX < 0) {
					newX = 0;
				}
				if(newX > my.imagesDivWidth) {
					newX = my.imagesDivWidth;
				}
				my.Touch.x = newX;
				var imageID = Math.round(newX / (my.imagesDivWidth / max));
				imageID = max - imageID;
				if(my.imageID !== imageID) {
					if(my.circular) {
						imageID = imageID + my.imageFocusMax;
					}
					my.glideOnEvent(imageID);
				}
				my.Helper.suppressBrowserDefault(e);
			}
		},

		stop: function() {
			my.Touch.stopX = my.Touch.x;
			my.Touch.busy = false;
		}
	};

	this.Key = {
		init: function() {
			document.onkeydown = function(event){ my.Key.handle(event); };
		},
		handle: function(event) {
			var charCode  = my.Key.get(event);
			switch (charCode) {
				case 39:
					my.MouseWheel.handle(-1);
					break;

				case 37:
					my.MouseWheel.handle(1);
					break;
			}
		},

		get: function(event) {
			event = event || window.event;
			return event.keyCode;
		}
	};

	this.Helper = {
		addEvent: function(obj, type, fn) {
			if(obj.addEventListener) {
				obj.addEventListener(type, fn, false);
			}
			else if(obj.attachEvent) {
				obj["e"+type+fn] = fn;
				obj[type+fn] = function() { obj["e"+type+fn]( window.event ); };
				obj.attachEvent( "on"+type, obj[type+fn] );
			}
		},

		removeEvent: function( obj, type, fn ) {
			if (obj.removeEventListener) {
				obj.removeEventListener( type, fn, false );
			}
			else if (obj.detachEvent) {
				if(obj[type+fn] === undefined) {
					alert('Helper.removeEvent » Pointer to detach event is undefined - perhaps you are trying to detach an unattached event?');
				}
				obj.detachEvent( 'on'+type, obj[type+fn] );
				obj[type+fn] = null;
				obj['e'+type+fn] = null;
			}
		},

		setOpacity: function(object, value) {
			if(my.opacity === true) {
				object.style.opacity = value/10;
				object.style.filter = 'alpha(opacity=' + value*10 + ')';
			}
		},

		createDocumentElement: function(type, id, optionalClass) {
			var element = document.createElement(type);
			element.setAttribute('id', my.ImageFlowID+'_'+id);
			if(optionalClass !== undefined) {
				id += ' '+optionalClass;
			}
			my.Helper.setClassName(element, id);
			return element;
		},

		setClassName: function(element, className) {
			if(element) {
				element.setAttribute('class', className);
				element.setAttribute('className', className);
			}
		},

		suppressBrowserDefault: function(e) 	{
			if(e.preventDefault) {
				e.preventDefault();
			}
			else {
				e.returnValue = false;
			}
			return false;
		},

		addResizeEvent: function() {
			var otherFunctions = window.onresize;
			if(typeof window.onresize != 'function') {
				window.onresize = function() {
					my.refresh();
				};
			}
			else {
				window.onresize = function(){
					if (otherFunctions) {
						otherFunctions();
					}
					my.refresh();
				};
			}
		}
	};
}


var domReadyEvent ={
	name: "domReadyEvent",
	events: {},
	domReadyID: 1,
	bDone: false,
	DOMContentLoadedCustom: null,

	add: function(handler) {
		if (!handler.$$domReadyID) {
			handler.$$domReadyID = this.domReadyID++;

			if(this.bDone) {
				handler();
			}

			this.events[handler.$$domReadyID] = handler;
		}
	},

	remove: function(handler) {
		if (handler.$$domReadyID) {
			delete this.events[handler.$$domReadyID];
		}
	},

	run: function() {
		if (this.bDone) {
			return;
		}

		this.bDone = true;

		for (var i in this.events) {
			this.events[i]();
		}
	},

	schedule: function() {
		if (this.bDone) {
			return;
		}

		if(/KHTML|WebKit/i.test(navigator.userAgent)) {
			if(/loaded|complete/.test(document.readyState)) {
				this.run();
			}
			else {
				setTimeout(this.name + ".schedule()", 100);
			}
		}
		else if(document.getElementById("__ie_onload")) {
			return true;
		}

		if(typeof this.DOMContentLoadedCustom === "function") {
			if(typeof document.getElementsByTagName !== 'undefined' && (document.getElementsByTagName('body')[0] !== null || document.body !== null)) {
				if(this.DOMContentLoadedCustom()) {
					this.run();
				}
				else {
					setTimeout(this.name + ".schedule()", 250);
				}
			}
		}
		return true;
	},

	init: function() {
		if(document.addEventListener) {
			document.addEventListener("DOMContentLoaded", function() { domReadyEvent.run(); }, false);
		}
		setTimeout("domReadyEvent.schedule()", 100);
		function run() {
			domReadyEvent.run();
		}

		if(typeof addEvent !== "undefined") {
			addEvent(window, "load", run);
		}
		else if(document.addEventListener) {
			document.addEventListener("load", run, false);
		}
		else if(typeof window.onload === "function") {
			var oldonload = window.onload;
			window.onload = function() {
				domReadyEvent.run();
				oldonload();
			};
		}
		else {
			window.onload = run;
		}
	}
};

var domReady = function(handler) { domReadyEvent.add(handler); };
domReadyEvent.init();

domReady(function()
{
	var instanceOne = new ImageFlow();
	instanceOne.init({ ImageFlowID:'myImageFlow' });
});



$(document).ready(function() {
	if ( document.getElementById('external_script2') ) {
		document.getElementById('external_script2').src = 'includes/mod_banner.asp?b=728x90';
	}
	if ( document.getElementById('external_script3') ) {
		document.getElementById('external_script3').src = 'includes/mod_banner.asp?b=160x300';
	}
	$(".video").fancybox({
		ajax : {
			type	: "GET"
		}
	});
});

function showMedia(id,title) {
	$.fancybox(
		'',
		{
		'width'				: 500,
		'height'			: 400,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'padding'			: 0,
		'href'				: 'video.asp?id='+id,
		'type'				: 'iframe',
		'title'				: title
		}
	);
}

function showLogin() {
	$.fancybox(
		'',
		{
			'autoDimensions': false,
			'width'         : 400,
			'height'        : 200,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'padding'		: 0,
			'href'			: 'login.asp',
			'type'			: 'iframe'
		}
	);
}
function showRegister() {
	$.fancybox(
		'',
		{
			'autoDimensions': false,
			'width'         : 480,
			'height'        : 400,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'padding'		: 0,
			'href'			: 'register.asp',
			'type'			: 'iframe'
		}
	);
}
function showWMRegister() {
	$.fancybox(
		'',
		{
			'autoDimensions': false,
			'width'         : 480,
			'height'        : 450,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'padding'		: 0,
			'href'			: 'registerwm.asp',
			'type'			: 'iframe'
		}
	);
}
function showContact() {
	$.fancybox(
		'',
		{
			'autoDimensions': false,
			'width'         : 480,
			'height'        : 440,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'padding'		: 0,
			'href'			: 'contact.asp',
			'type'			: 'iframe'
		}
	);
}
function createAjax() {
	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("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}
function postAjax(xmlHttp,url,parameters) {
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");
	xmlHttp.setRequestHeader("Pragma","no-cache");
	xmlHttp.setRequestHeader("Expires", 0);
	xmlHttp.send(parameters);
}


function getAjax(xmlHttp,url) {
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function videoOnStart() {
	var xmlHttp = createAjax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			var res = xmlHttp.responseText;
		}
	}
	getAjax(xmlHttp,"videoonstart.asp");
}
function videoOnStop() {
	var xmlHttp = createAjax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			var res = xmlHttp.responseText;
		}
	}
	getAjax(xmlHttp,"videoonstop.asp");
}
function chkAvail(title) {
	var xmlHttp = createAjax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			var res = xmlHttp.responseText.split('::');
			if ( res[0] == 1 ) {
				window.parent.document.getElementById('membertime').innerHTML=res[1];
				window.parent.document.getElementById('fancybox-title-main').innerHTML=title + ' - <strong>' + res[1] +'</strong>';
			}
			if ( res[0] == 2 ) {
				document.location='video.asp?id='+res[1];
				window.parent.document.getElementById('membertime').innerHTML=res[2];
				window.parent.document.getElementById('fancybox-title-main').innerHTML=title + ' - <strong>' + res[2] +'</strong>';
			}
		}
	}
	getAjax(xmlHttp,"videochkavail.asp");
}

function paypaypal() {
	var xmlHttp = createAjax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('formContainer').innerHTML = xmlHttp.responseText;
			if ( document.paypalForm ) {
				document.paypalForm.submit();
			}
		}
	}
	getAjax(xmlHttp,"paypal.asp");
}

function getPage(page) {
	document.mymovieForm.p.value=page;
	document.mymovieForm.submit();
}

