

$.fn.hasAttr = function(name){  
	if(this.attr(name) !== undefined )
		return true;
	else
		return false;
};
	
//IMAGE PRELOAD
var preloaded = new Array();
function preload_images() {
	for (var i = 0; i < arguments.length; i++){
		preloaded[i] = document.createElement('img');
		preloaded[i].setAttribute('src',imageDir + arguments[i]);
	};
};


//EMPTY	
function isEmpty(variable)
{
	
	if( variable == 'undefined' || variable == 'NaN' || variable == '' || typeof( variable ) == 'undefined') 
		return true;
		
	return false; 	
}

//ISSET	
function isset( variable ){
	return( typeof( variable ) != 'undefined' );
}

//REPLACE
function replace(f, r, s){
	var ra = r instanceof Array, sa = s instanceof Array, l = (f = [].concat(f)).length, r = [].concat(r), i = (s = [].concat(s)).length;
	while(j = 0, i--)
		while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j < l);
	return sa ? s : s[0];
}

function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}
function doRound(x, places) {
  return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
}
function IncludeJavaScript(jsFile)
{
   $("head").append('<script type="text/javascript" src="' + php_root + '/js/' + jsFile + '.js"></scr' + 'ipt>');
}
function Include(jsFile)
{ 
	IncludeJavaScript(jsFile); 
}
function IncludeJS(jsFile)
{ 
	IncludeJavaScript(jsFile); 
}

function IncludeJSCombine(jsFile)
{
	$("head").append('<script type="text/javascript" src="' + jsFile + '.js"></scr' + 'ipt>');
}

function IncludeCSS(cssFile)
{
   $("head").append('<link rel="stylesheet" href="css/'+ cssFile +'.css" />');
}

$(document).ready(function(){

	//INPUTS 
	$(".text,.text_small").focus(function () {
		$(this).addClass('focus');  	
	});
	$(".text,.text_small").blur(function () {
		$(this).removeClass('focus');  	
	});

	//CLEAR
	var old;
	$('.clear').click(function(){ 
		old = this.value;
		if( $(this).attr('title') != '1')
			this.value = '';
	}).blur(function () {
		if(this.value == '')
			this.value = old;
		else
			$(this).attr('title', '1');	
	});
	
	//PROPAGE CENTER
	$('.jCenter img').each(function() {
		var width = $(this).attr('width'); 
		var height = $(this).attr('height');
	 	if(width == '0')
			width = $(this).css('width');
		if(height == '0')
			height = $(this).css('height');
		
		$(this).css({left: '50%', marginLeft: -parseInt(width)/2});
		$(this).css({top: '50%',  marginTop : -parseInt(height)/2}); 
		$(this).show();
	}); 
	
	//ACTIVE 
	$(".listing li").hover(
      function () {
			$(this).addClass('active');
      }, function () {
	  		$(this).removeClass("active");
      }
    );
	/*
	$('.activetd').click(function() {
		$(this).parents('table:first').find('td').removeClass('active');
		$(this).parent().addClass('active');	
	});
	
	$('.activli').click(function() {
		$(this).parents('ul').find('li').removeClass('active');
		$(this).parents('li').addClass('active');	
	});
	*/
	
	//TRACE
 	$('.trace').click(function() {
	$.ajax({
		type: "GET",
		dataType: "html",
		url: jQuery.root+"/ajax/trace.php",
		data: { name: 'Kliknięcie', desc: $(this).attr("title") }
	});});
	
	$('a[target="_blank"]').click(function() {
	$.ajax({
        type: "GET",
		dataType: "html",
        url: jQuery.root+"/ajax/trace.php",
		data: { name: 'Zewnętrzny link' , desc: $(this).attr("href") }
    });});
	
	

	//AJAX
	$(".ajax_submit").live("click", function(){
		IncludeJS('jquery.boxy'); 
		
		if($(this).attr('title').length > 0)
			titleOn = true;
		else
			titleOn = false; 
		
	
		var form = $(this).parents('form:first');
		var href = form.attr('action');
	
		Boxy.load(href , {title: $(this).attr('title'), titleOn: titleOn, closeable: true, dataType: 'json', type: form.attr('method')},  form.serialize(true) , false);
		return false;
	});

	
	$(".ajax_get").live("click", function(){
		IncludeJS('jquery.boxy'); 
		
		var href = $(this).attr('href'); 
		
		var jgn 		= false;
		var dataType 	= 'json';
		
		if($(this).hasClass('html')) 
			dataType = 'html';
			
		if($(this).hasClass('jgn')) 
			jgn = true; 	
		
		if($(this).attr('title').length > 0)
			titleOn = true; 	
		else
			titleOn = false; 
			
		Boxy.load(href, {title: $(this).attr('title'), titleOn: titleOn, dataType: dataType, type:'POST', jgn:jgn, draggable:true}, href[1]);
		
		return false;
	});

});	

/**
* Name: piroBox v.1.2.2
* Date: May 2010
* Autor: Diego Valobra (http://www.pirolab.it),(http://www.diegovalobra.com)
* Version: 1.2.2
* Licence: CC-BY-SA http://creativecommons.org/licenses/by-sa/2.5/it/
**/

(function($) {
	$.fn.piroBox = function(opt) {
		opt = jQuery.extend({
		my_speed : null,
		close_speed : 300,
		bg_alpha : 0.5,
		close_all : '.piro_close,.piro_overlay',
		slideShow : null,
		slideSpeed : null
		}, opt);

		function start_pirobox() {
		  var corners = 
			  '<tr>'+					   
			  '<td colspan="3" class="pirobox_up"></td>'+
			  '</tr>'+	
			  '<tr>'+	
			  '<td class="t_l"></td>'+
			  '<td class="t_c"></td>'+
			  '<td class="t_r"></td>'+
			  '</tr>'+
			  '<tr>'+
			  '<td class="c_l"></td>'+
			  '<td class="c_c"><span><span></span></span><div></div></td>'+
			  '<td class="c_r"></td>'+
			  '</tr>'+
			  '<tr>'+
			  '<td class="b_l"></td>'+
			  '<td class="b_c"></td>'+
			  '<td class="b_r"></td>'+
			  '</tr>'+
			  '<tr>'+
			  '<td colspan="3" class="pirobox_down"></td>'+
			  '</tr>';
			var window_height =  $(document).height();
			var bg_overlay = $(jQuery('<div class="piro_overlay"></div>').hide().css({'opacity':+opt.bg_alpha,'height':window_height+'px'}));
			var main_cont = $(jQuery('<table class="pirobox_content" cellpadding="0" cellspacing="0"></table>'));
			var caption = $(jQuery('<div class="caption"></div>'));
			var piro_nav = $(jQuery('<div class="piro_nav"></div>'));
			var piro_close = $(jQuery('<a href="#close" class="piro_close" title="close"></a>'));
			var piro_play = $(jQuery('<a href="#play" class="play" title="play slideshow"></a>'));
			var piro_stop = $(jQuery('<a href="#stop" class="stop" title="stop slideshow"></a>'));
			var piro_prev = $(jQuery('<a href="#prev" class="piro_prev" title="previous image"></a>'));
			var piro_next = $(jQuery('<a href="#next" class="piro_next" title="next image"></a>'));				
			$('body').append(bg_overlay).append(main_cont);
			main_cont.append(corners);
			$('.pirobox_up').append(piro_close);
			$('.pirobox_down').append(piro_nav);
			$('.pirobox_down').append(piro_play);
			piro_play.hide();
			$('.pirobox_down').append(piro_prev).append(piro_next);
			piro_nav.append(caption);
			var my_nav_w = piro_prev.width();
			main_cont.hide();
			var my_gall_classes = $("a[class^='pirobox']");
			var map = new Object();
				for (var i=0; i<my_gall_classes.length; i++) {
					var it=$(my_gall_classes[i])
					map['a.'+it.attr('class')]=0;
				}
			var gall_settings = new Array();
				for (var key in map) {
					gall_settings.push(key);
				}
				for (var i=0; i<gall_settings.length; i++) {
					$(gall_settings[i]).each(function(rel){this.rel = rel+1 + "&nbsp;of&nbsp;" + $(gall_settings[i]).length;});
						var add_first = $(gall_settings[i]+':first').addClass('first');
						var add_last = $(gall_settings[i]+':last').addClass('last');
				}						
			$(my_gall_classes).each(function(rev){this.rev = rev+0});
			var imgCache = $(my_gall_classes).each(function(){this.href});
			var hidden = $('body').append('<div id="imgCache" style="display:none"></div').children('#imgCache');
			$.each(imgCache, function (i,val) {
				$('<div/>').css({'background':'url('+val+')'/*,'width':'600px','height':'200px'*/}).appendTo(hidden);
			});
			var piro_gallery = $(my_gall_classes);
			$.fn.fixPNG = function() {
				return this.each(function () {
					var image = $(this).css('backgroundImage');
					if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
						image = RegExp.$1;
						$(this).css({
							'backgroundImage': 'none',
							'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=" + ($(this).css('backgroundRepeat') == 'no-repeat' ? 'crop' : 'scale') + ", src='" + image + "')"
						}).each(function () {
							var position = $(this).css('position');
							if (position != 'absolute' && position != 'relative')
								$(this).css('position', 'relative');
						});
					}
				});
			};
			$.browser.msie6 =($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent));
			if( $.browser.msie6 && !/MSIE 8\.0/i.test(window.navigator.userAgent)) {
				$('.t_l,.t_c,.t_r,.c_l,.c_r,.b_l,.b_c,.b_r,a.piro_next, a.piro_prev,a.piro_prev_out,a.piro_next_out,.c_c,.piro_close,a.play,a.stop').fixPNG();
				var ie_w_h =  $(document).height();
				bg_overlay.css('height',ie_w_h+ 'px'); 
			}
			if( $.browser.msie) {
			opt.close_speed = 0;
			}
			$(window).resize(function(){
				var new_w_bg = $(document).height();
				bg_overlay.css({'visibility':'visible','height':+ new_w_bg +'px'});				  
			});	
			piro_prev.add(piro_next).bind('click',function(c) {
				c.preventDefault();
				var image_count = parseInt($(piro_gallery).filter('.item').attr('rev'));
				var start = $(this).is('.piro_prev_out,.piro_prev') ? $(piro_gallery).eq(image_count - 1) : $(piro_gallery).eq(image_count + 1);
				if(!start.size()) {
					start = $(this).is('.piro_prev_out,.piro_prev') ? $(piro_gallery).eq($(piro_gallery).size() - 1) : $(piro_gallery).eq(0);
				}
				start.click();
				piro_close.add(caption).add(piro_next).add(piro_prev).css('visibility','hidden');
			});
			$(piro_gallery).each(function(array) {
					var item = $(this);
					item.unbind(); 
					item.bind('click',function(c) {
						c.preventDefault();
						piro_open(item.attr('href'));
						var this_url = item.attr('href');
						//var descr = item.children('span').html();
						var descr = item.attr('title');	
						var number = item.attr('rel');
						if( descr == ""){
						caption.html('<p>'+ this_url+'<em class="number">' + number + '</em><a href='+ this_url +' class="link_to" target="_blank" title="Open Image in a new window"></a></p>');
						}else{
						caption.html('<p>'+ descr+'<em class="number">' + number + '</em><a href='+ this_url +' class="link_to" target="_blank" title="Open Image in a new window"></a></p>');
						}
						if(item.is('.last')){
							$('.number').css('text-decoration','underline');
							
						}else{
							$('.number').css('text-decoration','none');
							}				
						if(item.is('.first')){
							piro_prev.hide();
							piro_next.show();		
						}else{
							piro_next.add(piro_prev).show();		  
						}
						if(item.is('.last')){
							piro_prev.show();
							piro_next.hide();
							piro_play.css('width','0');	  
						}else{
							piro_play.css('width','40px');
							}
						if(item.is('.last') && item.is('.first') ){
							piro_prev.add(piro_next).hide();
							$('.number').hide();
							piro_play.remove();
						}					
							$(piro_gallery).filter('.item').removeClass('item');
							item.addClass('item');
							$('.c_c').removeClass('unique');		
					});
				});
				var piro_open = function(my_url) {
					piro_play.add(piro_stop).hide();
					piro_close.add(caption).add(piro_next).add(piro_prev).css('visibility','hidden');
					if(main_cont.is(':visible')) {
						$('.c_c div').children().fadeOut(300, function() {
							$('.c_c div').children().remove();
							load_img(my_url);
						});
					} else {
						$('.c_c div').children().remove();
						main_cont.show();
						bg_overlay.fadeIn(300,function(){
						load_img(my_url);
						});
					}
				}
				var load_img = function(my_url) {
				if(main_cont.is('.loading')) {return;}
				main_cont.addClass('loading');
				var img = new Image();
				img.onerror = function (){
					var main_cont_h = $(main_cont).height();
					main_cont.css({marginTop : parseInt($(document).scrollTop())-(main_cont_h/1.9)});
				  $('.c_c div').append('<p class="err_mess">There seems to be an Error:&nbsp;<a href="#close" class="close_pirobox">Close Pirobox</a></p>');
					$('.close_pirobox').bind('click',function(c) {
						c.preventDefault();
						piro_close.add(bg_overlay).add(main_cont).add(caption).add(piro_next).add(piro_prev).hide(0,function(){ img.src = '';});
						main_cont.removeClass('loading');
					});
				}
				img.onload = function() {
					var imgH = img.height;
					var imgW = img.width;
					var main_cont_h = $(main_cont).height();
					var w_H = $(window).height();
					var w_W = $(window).width();
					$(img).height(imgH).width(imgW).hide();
						$('.c_c div').animate({height:imgH+'px',width:imgW+'px'},opt.my_speed);
						var fix = imgH/w_H*2.3;
						if(w_H < imgH){h_fix = fix;}else{h_fix = 2;}
						main_cont.animate({
						height : (imgH+40) + 'px' ,
						width : (imgW+40) + 'px' , 
						marginLeft : '-' +((imgW)/2+20) +'px',
						marginTop : parseInt($(document).scrollTop())-(imgH/h_fix)},opt.my_speed, function(){
						$('.piro_nav,.caption').css({width:(imgW)+'px','margin-bottom':'10px'});
						$('.piro_nav').css('margin-left','-'+(imgW)/2+'px');
							var caption_height = caption.height();
							$('.c_c div').append(img);					
							piro_close.css('display','block');
							piro_next.add(piro_prev).add(piro_close).css('visibility','visible');
							caption.css({'visibility':'visible','display':'block','opacity':'0.8','overflow':'hidden'});
							main_cont.hover(function(){
								caption.stop().fadeTo(200,0.8);},
								function(){caption.stop().fadeTo(200,0);
								});
								$(img).fadeIn(300);
									main_cont.removeClass('loading');
									if(opt.slideShow === true){
									   piro_play.add(piro_stop).show();
									}else{
										 piro_play.add(piro_stop).hide();
									}	
							});			
						}
					img.src = my_url;
					$('html').bind("keyup", function (c) {
						 if(c.keyCode == 27) {
							c.preventDefault();
							if($(img).is(':visible') || $('.c_c>div>p>a').is('.close_pirobox')){
								$(piro_gallery).removeClass('slideshow').removeClass('item');
								piro_close.add(bg_overlay).add(main_cont).add(caption).add(piro_next).add(piro_prev).hide(0,function(){ img.src = '';});
								main_cont.removeClass('loading');
								clearTimeout(timer);
								$(piro_gallery).children().removeAttr('class');
								$('.stop').remove();
								$('.c_c').append(piro_play);
								$('.sc_menu').css('display','none');
								$('ul.sc_menu li a').removeClass('img_active').css('opacity','0.4');	
								piro_next.add(piro_prev).show().css({'top':'50%'});	
								$(piro_gallery).children().fadeTo(100,1);
							}
						}
					});
					$('html').bind("keyup" ,function(e) {
						 if ($('.item').is('.first')){
						}else if(e.keyCode == 37){
						e.preventDefault();
							if($(img).is(':visible')){
								clearTimeout(timer);
								$(piro_gallery).children().removeAttr('class');
								$('.stop').remove();
								$('.c_c').append(piro_play);
								piro_prev.click();
							}
						 }
					});
					$('html').bind("keyup" ,function(z) {
						if ($('.item').is('.last')){
						}else if(z.keyCode == 39){
						z.preventDefault();
							if($(img).is(':visible')){
								clearTimeout(timer);
								$(piro_gallery).children().removeAttr('class');
								$('.stop').remove();
								$('.c_c').append(piro_play);
								piro_next.click();
								//alert('click')
							}
						}
					});
					var win_h = $(window).height();
					piro_stop.bind('click',function(x){
						x.preventDefault();
						clearTimeout(timer);
						$(piro_gallery).removeClass('slideshow');
						$('.stop').remove();
						$('.pirobox_down').append(piro_play);
						piro_next.add(piro_prev).css('width',my_nav_w+'px');
					});
					piro_play.bind('click',function(w){
						w.preventDefault();
						clearTimeout(timer);
						if($(img).is(':visible')){
						$(piro_gallery).addClass('slideshow');
						$('.play').remove();
						$('.pirobox_down').append(piro_stop);
						}
						piro_next.add(piro_prev).css({'width':'0px'});
						return slideshow();
					});
				  $(opt.close_all).bind('click',function(c) {
					$(piro_gallery).removeClass('slideshow');
					clearTimeout(timer);
					if($(img).is(':visible')){
						c.preventDefault();
						piro_close.add(bg_overlay).add(main_cont).add(caption).add(piro_next).add(piro_prev).hide(0,function(){ img.src = '';});
						main_cont.removeClass('loading');
						$(piro_gallery).removeClass('slideshow');
						piro_next.add(piro_prev).css('width',my_nav_w+'px').hide();
						$('.stop').remove();
						$('.pirobox_down').append(piro_play);
						piro_play.hide();
					}
				  });	
					if(opt.slideShow === true){
						function slideshow(){
							if( $(piro_gallery).filter('.item').is('.last')){
							clearTimeout(timer);
							$(piro_gallery).removeClass('slideshow');
							$('.stop').remove();
							$('.pirobox_down').append(piro_play);
							piro_next.add(piro_prev).css('width',my_nav_w+'px');								 
							} else if($(piro_gallery).is('.slideshow' ) && $(img).is(':visible')){
								clearTimeout(timer);
								piro_next.click();
							}
						}					
						var timer = setInterval(slideshow,opt.slideSpeed*1000 );
					}


				}
			}

		start_pirobox();
	}
})(jQuery);

/*
    anythingSlider v1.3
    
    By Chris Coyier: http://css-tricks.com
    with major improvements by Doug Neiner: http://pixelgraphics.us/
    based on work by Remy Sharp: http://jqueryfordesigners.com/


	To use the navigationFormatter function, you must have a function that
	accepts two paramaters, and returns a string of HTML text.
	
	index = integer index (1 based);
	panel = jQuery wrapped LI item this tab references
	@return = Must return a string of HTML/Text
	
	navigationFormatter: function(index, panel){
		return index + " Panel"; // This would have each tab with the text 'X Panel' where X = index
	}
*/

(function($) {
	
    $.anythingSlider = function(el, options) {
      
    // To avoid scope issues, use 'base' instead of 'this'
    // to reference this class from internal events and functions.
      var base = this;
        
    // Access to jQuery and DOM versions of element
      base.$el = $(el);
      base.el = el; 

		// Set up a few defaults
      base.currentPage = 1;
    	base.timer = null;
  		base.playing = false;

    // Add a reverse reference to the DOM object
      base.$el.data("AnythingSlider", base);
      
      base.init = function() {
        
        base.options = $.extend({},$.anythingSlider.defaults, options);
			
			// Cache existing DOM elements for later 
		base.$wrapper = base.$el.find('> div').css('overflow', 'hidden');
        base.$slider  = base.$wrapper.find('> ul');
        base.$items   = base.$slider.find('> li');
        base.$single  = base.$items.filter(':first');
        
      // Get the details
        base.singleWidth = base.$single.outerWidth();
        base.pages = base.$items.length;
        
        if (base.pages === 1) {
              base.options.autoPlay = false;
        }

      // Build the navigation if needed
        base.buildNavigation();

      // Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
			// This supports the "infinite" scrolling
			// Ensures any cloned elements with ID's have unique ID's
			  var $itemClone = base.$items.filter(':last').clone().addClass('cloned');
			  if ($itemClone.attr("id") != "") {
          base.$items.filter(':first').before($itemClone.attr('id', ($itemClone.attr('id') + "-cloned")));
        } else {
          base.$items.filter(':first').before($itemClone);
        }

        $itemClone = base.$items.filter(':first').clone().addClass('cloned');
        if ($itemClone.attr("id") != '') {
          base.$items.filter(':last' ).after($itemClone.attr('id', ($itemClone.attr('id') + "-cloned")));
        } else {
          base.$items.filter(':last' ).after($itemClone);
        }

			// We just added two items, time to re-cache the list
        base.$items = base.$slider.find('> li'); // reselect
            
			// Setup our forward/backward navigation
			if (base.pages > 1) {
			  base.buildNextBackButtons();
			}
		
			// If autoPlay functionality is included, then initialize the settings
			if (base.options.autoPlay) {
				base.playing = !base.options.startStopped; // Sets the playing variable to false if startStopped is true
				base.buildAutoPlay();
			};
			
			// If pauseOnHover then add hover effects
			if (base.options.pauseOnHover) {
				base.$el.hover(function() {
					base.clearTimer();
				}, function() {
					base.startStop(base.playing);
				});
			}
			
			// If a hash can not be used to trigger the plugin, then go to page 1
			if ((base.options.hashTags == true && !base.gotoHash()) || base.options.hashTags == false) {
				base.setCurrentPage(1);
			};
    };

		base.gotoPage = function(page, autoplay) {
			// When autoplay isn't passed, we stop the timer
			if (autoplay !== true) autoplay = false;
			if (!autoplay) base.startStop(false);
			
			if (typeof(page) == "undefined" || page == null) {
				page = 1;
				base.setCurrentPage(1);
			};
			
			// Just check for bounds
			if (page > base.pages + 1) page = base.pages;
			if (page < 0 ) page = 1;

			var dir = page < base.currentPage ? -1 : 1,
            n = Math.abs(base.currentPage - page),
         left = base.singleWidth * dir * n;
			
			base.$wrapper.filter(':not(:animated)').animate({
           scrollLeft : '+=' + left
        }, base.options.animationTime, base.options.easing, function () {
           
          if (page == 0) {
              base.$wrapper.scrollLeft(base.singleWidth * base.pages);
		          page = base.pages;
          } else if (page > base.pages) {
              base.$wrapper.scrollLeft(base.singleWidth);
              // reset back to start position
              page = 1;
              
      };
      
	    base.setCurrentPage(page);
	
      });
		};
		
		base.setCurrentPage = function(page, move) {
			// Set visual
			if (base.options.buildNavigation){
				base.$nav.find('.cur').removeClass('cur');
				$(base.$navLinks[page - 1]).addClass('cur');
			};
			
			// Only change left if move does not equal false
			if (move !== false) base.$wrapper.scrollLeft(base.singleWidth * page);

			// Update local variable
			base.currentPage = page;
		};
		
		base.goForward = function(autoplay) {
			if(autoplay !== true) autoplay = false;
			base.gotoPage(base.currentPage + 1, autoplay);
		};
		
		base.goBack = function() {
			base.gotoPage(base.currentPage - 1);
		};
		
		// This method tries to find a hash that matches panel-X
		// If found, it tries to find a matching item
		// If that is found as well, then that item starts visible
		base.gotoHash = function(){
			if (/^#?panel-\d+$/.test(window.location.hash)) {
				var index = parseInt(window.location.hash.substr(7));
				var $item = base.$items.filter(':eq(' + index + ')');
				if ($item.length != 0) {
					base.setCurrentPage(index);
					return true;
				};
			};
			return false; // A item wasn't found;
		};
        
		// Creates the numbered navigation links
		base.buildNavigation = function() {
			base.$nav = $("<div class='thumbNav'><ul/></div>").prependTo(base.$el);
			
			if (base.options.buildNavigation && (base.pages > 1)) {
  			base.$items.each(function(i,el) {
  				var index = i + 1;
  				var $a = $("<a href='#'></a>");
				
  				// If a formatter function is present, use it
  				if (typeof(base.options.navigationFormatter) == "function") {
  					$a.html(base.options.navigationFormatter(index, $(this)));
  				} else {
  					$a.text(index);
  				}
				
  				$a.click(function(e) {
            base.gotoPage(index);
            if (base.options.hashTags) base.setHash('panel-' + index);
  				  e.preventDefault();
  				});
				
  				$("ul", base.$nav).append($a);
          $a.wrap("<li />");
  			});
  			base.$navLinks = base.$nav.find('li > a');
			
  		}
		};
		
		// Creates the Forward/Backward buttons
		base.buildNextBackButtons = function() {
			var $forward = $('<li class="arrow forward"><a href="#"></a></li>'),
			  	$back    = $('<li class="arrow back"><a href="#"></a></li>');
				
    // Bind to the forward and back buttons
      $back.click(function(e) {
          base.goBack();
				  e.preventDefault();
      });
      $forward.click(function(e) {
          base.goForward();
				  e.preventDefault();
      });

		// Append elements to page
			$("ul", base.$nav).prepend($back).append($forward);
		};
		
		// Creates the Start/Stop button
		base.buildAutoPlay = function(){

			base.$startStop = $("<a href='#' class='start-stop'></a>").html(base.playing ? base.options.stopText :  base.options.startText);
			base.$el.prepend(base.$startStop);            
      base.$startStop.click(function(e) {
				base.startStop(!base.playing);
				e.preventDefault();
      });

			// Use the same setting, but trigger the start;
			base.startStop(base.playing);
		};
		
		// Handles stopping and playing the slideshow
		// Pass startStop(false) to stop and startStop(true) to play
		base.startStop = function(playing) {
			if (playing !== true) playing = false; // Default if not supplied is false
			
			// Update variable
			base.playing = playing;
			
			// Toggle playing and text
			if (base.options.autoPlay) base.$startStop.toggleClass("playing", playing).html( playing ? base.options.stopText : base.options.startText );
			
			if (playing){
				base.clearTimer(); // Just in case this was triggered twice in a row
				base.timer = window.setInterval(function() {
					base.goForward(true);
				}, base.options.delay);
			} else {
				base.clearTimer();
			};
		};
		
		base.clearTimer = function(){
			// Clear the timer only if it is set
			if(base.timer) window.clearInterval(base.timer);
		};
		
		// Taken from AJAXY jquery.history Plugin
		base.setHash = function (hash) {
			// Write hash
			if ( typeof window.location.hash !== 'undefined' ) {
				if ( window.location.hash !== hash ) {
					window.location.hash = hash;
				};
			} else if ( location.hash !== hash ) {
				location.hash = hash;
			};
			
			// Done
			return hash;
		};
		// <-- End AJAXY code

		// Trigger the initialization
        base.init();
    };

    $.anythingSlider.defaults = {
      easing: "swing",                // Anything other than "linear" or "swing" requires the easing plugin
      autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
      startStopped: false,            // If autoPlay is on, this can force it to start stopped
      delay: 3000,                    // How long between slide transitions in AutoPlay mode
      animationTime: 600,             // How long the slide transition takes
      hashTags: true,                 // Should links change the hashtag in the URL?
      buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
      pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
  		startText: "Start",             // Start text
  		stopText: "Stop",               // Stop text
  		navigationFormatter: null,      // Details at the top of the file on this use (advanced use)
  		forwardText: "&gt;",            // Link text used to move the slider forward
  		backText: "&lt;"                // Link text used to move the slider back
    };
	
    $.fn.anythingSlider = function(options) {
      
		  if (typeof(options) == "object"){
		    return this.each(function(i){			
				(new $.anythingSlider(this, options));

	      // This plugin supports multiple instances, but only one can support hash-tag support
				// This disables hash-tags on all items but the first one
				options.hashTags = false;
	    });	
	    
		} else if (typeof(options) == "number") {

			return this.each(function(i) {
				var anySlide = $(this).data('AnythingSlider');
				if (anySlide) {
					anySlide.gotoPage(options);
				}
			});
			
		}
		
  };
	
})(jQuery);	
