(function( $ ){
	

	$.fn.promo = function(speed,duration){
		var $this = $(this);
		$('.switcher li').clearQueue();
		$('.switcher li').unbind('click');

		var i = $this.index();
		//alert(i);
	   
		var $activeSlide = $('.slider li.active');
		var $thisSlide = $('.slider li').eq(i);
		$activeSlide.attr('class','');
		$thisSlide.attr('class','active');

		var offset = $activeSlide.position().left - $thisSlide.position().left;
		if (offset >= 0){
			$('.slider').animate({right: "-="+offset }, 700, 'swing');
		} else {
			$clone = $thisSlide.clone();
			$clone.insertAfter($activeSlide).attr('class','clone');
			offset = $activeSlide.position().left - $clone.position().left;
			$('.slider').animate({right: "-="+offset }, 700, 'swing', function(){
				$('.slider').css('right',($thisSlide.position().left-$('.slider').width())+$thisSlide.width());
				$('.slider li.clone').remove();
			});
		}
		
		$this.attr('class', 'selected');
		$('div.gallery-box').animate({height: "0px"}, 700, 'swing' , function(){
			$(this).delay(400).animate({height: '340px'}, 700, 'swing', function(){
				$('.switcher li').bind('click', $.fn.promo);
			});
			
			$('.switcher li.active').attr('class','');
			$('.switcher li.selected').attr('class','active');
			
			var i = $('.switcher li.active').index();
			$('.holder li.active').attr('class','');
			$('.holder li').eq(i).attr('class','active');
		});
		
		var next;
		(i == $this.siblings().length)? next=0 : next= (i+1);
		
		$this.delay(11000).queue(function() {
		$('.switcher li').eq(next).promo(speed,duration);
		$this.dequeue(); 
		return $this;
		});
		
	};
})( jQuery );


$(document).ready(function(){
	$('.switcher li').click(function(){
		//$(this).promo(500,9000);
		$(this).promo(1000,11000);
        $(this).blur();
    });
	
    $('div.cloud').mouseenter(function(){
        $this = $(this);
        $this.animate({left: '+=6'}, 200, 'swing').animate({left: '-=10'}, 200, 'swing').animate({left: '+=4'}, 200, 'swing');
    });
    
    $('.switcher li').eq(1).delay(11000).queue(function(){
		//$(this).promo(500,9000);
		$(this).promo(1000,11000);
		//$(this).dequeue();
	});

    if ($("#sidebar .current_page_item").has("ul.children").length<= 0){
        $("#sidebar .current_page_item").addClass('active').removeClass('current_page_item');
    }
    
	$('.menu li.active').has('ul').addClass('issubmenu');
	var noresults = $('#blocks').height();
	if (noresults==0){
		$('.noreultsfound').show();
	}
	
	
	$('#service-links').not(':has(li)').remove();
		
});

$(function() {
if($.browser.msie){
$('div').each(function(i) {
if($(this).css('position')!='absolute') $(this).css('zIndex', 1000 - (i * 10));
});
}
})

/******************** PAGINATION ************************/
$.fn.paginate = function(options) {
          var options = jQuery.extend({
               content: 'TBODY TR',
               limit: 5
          },options);

     return this.each(function() {

          var page = {};
               page.parent = $(this),
               page.content = (page.parent.is('TABLE')) ? page.parent.find(options.content) : page.parent.children(options.content),
               page.total = Math.ceil(page.content.size() / options.limit),
               page.display = page.content.css('display'),
               page.prev = 0,
               page.next = 2;

          page.content.slice(options.limit).css('display', 'none').addClass('ui-helper-hidden');

          $(document.createElement("DIV")).addClass("link-container")[(page.parent.is('TABLE')) ? 'insertAfter' : 'appendTo'](this);

          page.linkContainer = (page.parent.is('TABLE')) ? page.parent.next('.link-container:first') : page.parent.find('.link-container:first');

         $(document.createElement("A")).addClass("pagination-link previous ui-state-default").attr('href', 'previous').attr('title', 'Previous page').attr('rel', 'nofollow').text('<').appendTo(page.linkContainer);

          for(var num=0;  num < page.total;   num++){
               var offset = num + 1,
                     min = (offset * options.limit) - (options.limit),
                     max = (offset * options.limit);

               $(document.createElement("A")).addClass("pagination-link numeric ui-state-default").attr('href', offset).attr('title', 'Page '+offset+'').attr('rel', 'nofollow').text(offset).appendTo(page.linkContainer);

               page[offset] = page.content.slice(min, [max]);
          };

          $(document.createElement("A")).addClass("pagination-link next ui-state-default").attr('href', 'next').attr('title', 'Next page').attr('rel', 'nofollow').text('>').appendTo(page.linkContainer);

          page.wraps =  page.linkContainer.find('.paginationWrap');
          page.anchors = page.linkContainer.find('A');

          page.anchors.bind('mouseenter mouseleave', function(e){

               this.self = $(this);
               (e.type === 'mouseenter') ? this.self.addClass('ui-state-hover') : this.self.removeClass('ui-state-hover');
           }).eq(1).addClass('ui-state-active');

         page.anchors.bind('click', function(e){
               e.preventDefault();

               if($(this).is('.ui-state-active')){
                    return false;
               }

               this.siblings = $(this).siblings('.ui-state-active:first');

               if($(this).is('.previous')) {

                    if(page.prev === 0){
                         return false;
                    };

                    this.link = $(this).siblings('A[href= ' + page.prev + ']');
                    this.link.add(this.siblings).toggleClass('ui-state-active');

                    page.content.css('display', 'none').addClass('ui-helper-hidden');
                    page[page.prev].css('display', page.display).removeClass('ui-helper-hidden');

                    page.prev--,
                    page.next--;

               } else if($(this).is('.next')) {

                    if(page.next === (page.total + 1)){
                         return false;
                    };

                    this.link = $(this).siblings('A[href= ' + page.next + ']');
                    this.link.add(this.siblings).toggleClass('ui-state-active');

                    page.content.css('display', 'none').addClass('ui-helper-hidden');
                    page[page.next].css('display', page.display).removeClass('ui-helper-hidden');

                    page.prev++,
                    page.next++;

               } else {

                    this.link = $(this);
                    this.link.add(this.siblings).toggleClass('ui-state-active');

                    this.offset = parseInt(this.link.attr('href'));

                    page.content.css('display', 'none').addClass('ui-helper-hidden');
                    page[this.offset].css('display', page.display).removeClass('ui-helper-hidden');

                    page.prev = this.offset - 1,
                    page.next = this.offset + 1;
               }

           });
           return this;
      });
};
