    /**
     * @author Ahmet ONOL
     * @copyright 2010 - ICON Perception Managemet Co.
     * @company ICON Perception Managemet Co.
     * @email contact@icon-pm.com
     * @web http://www.icon-pm.com
     * @project Moonlight
     * @version 
     * @created 2010.5.5 11:19
     * @modified 2010.5.5
     * @modifier Ahmet ONOL
    **/ 
    

 (function($){
    $.fn.ntTabsAndSlides = function(options){
        var opts = $.extend({}, $.fn.ntTabsAndSlides.defaults, options);
        
        return this.each(function(){
            var $container = $(this);
			var o = opts;
			
            var pages = o.pages;
            var $navigation = $container.find(o.navigation);                      
            var $pageNavigations = $navigation.find('a');
            var currentClass = o.currentClass;
            var transition = o.transition;
            var transitionSpeed = o.transitionSpeed;
            var pagination = $pageNavigations.length;                       
            var lastPage = 0; // if pagination has next & previous buttons
            var autoSlide = o.autoSlide;
            var slideShowDelay = o.slideShowDelay;
            var thePage, timer;

            $container.find(pages).each(function(){
               $(this).hide();
            });
            
            $container.find(pages + ':first').show().addClass(currentClass);
            
            // enables tab key navigation
            $pageNavigations.hover(function(){
                                              
                
                var newscontent_height = $("#news-ticker").height();
                $(".news-nav").height(newscontent_height);
                
                // if previous button clicked
                if($(this).hasClass('pre') || $(this).parent().hasClass('pre')){
                    
                    pre = $navigation.find('.'+ currentClass).prev();
                    var p = $navigation.find('li').index(pre);
                    if(p == -1) { pre = $navigation.find('li:eq(' + lastPage + ')'); }                    
                    $navigation.find('.'+ currentClass).removeClass(currentClass);
                    pre.addClass(currentClass);
                    thePage = $(pre.find('a').attr('rel'));

                }
                
                // if next button clicked
                else if($(this).hasClass('next') || $(this).parent().hasClass('next')){ 
                    next = $navigation.find('.'+ currentClass).next();
                    var n = $navigation.find('li').index(next);
                    if(n == pagination - 1 || n == -1) { next = $navigation.find('li:eq(0)'); }
                    $navigation.find('.'+ currentClass).removeClass(currentClass);
                    next.addClass(currentClass);
                    
                    thePage = $(next.find('a').attr('rel'));
                }
                
                // or other page buttons clicked
                else {
                    if(!$(this).parent().hasClass(currentClass)){ 
                        $navigation.find('.'+ currentClass).removeClass(currentClass);
                        $(this).parent().addClass(currentClass);
                    }
                    
                    thePage = $($(this).attr('rel'));
                }
                    
                animatePage(thePage);

                
                return false;
            });
            
            if(autoSlide == true){
                startSlideShow();
                
                $(pages).hover(
                    function(){
                        stopSlideShow();
                    },
                    function(){
                        startSlideShow();
                    }
                );
            }
            
            function slideshow(){                
                var current = $navigation.find('.' + currentClass);
                var next = current.next();
                var n = $navigation.find('li').index(next);
                
                if(n == -1) { next = $navigation.find('li:eq(0)'); }
                
                if(next.hasClass('pre') || next.hasClass('next')){
                    next = $navigation.find('li:eq(1)');
                }                
                
                $(current).removeClass(currentClass);
                next.addClass(currentClass);
                    
                thePage = $(next.find('a').attr('rel'));
                
                animatePage(thePage);                                            
            }
            
            function stopSlideShow(){                                    
                clearInterval(timer);
            } 
            
            function startSlideShow(){
                timer = setInterval(slideshow, slideShowDelay); 
            }             
            
            function animatePage(page){
                currentPage = $container.find(pages + '.' + '.'+ currentClass);
                nextPage = page;
                
                
                    if(transition == 'fade'){
                        currentPage.fadeOut(transitionSpeed).queue(function(){
                            nextPage.fadeIn(transitionSpeed);
                            $(this).dequeue();
                        });
                        
                    }
                    
                    else if(transition == 'vslide'){
                        currentPage.slideUp(transitionSpeed);
                        nextPage.slideDown(transitionSpeed);
                    }
                    
                    // to work horizontal slide, pages should be wrapped with a overflow hidden layer having same width with the pages
                    else if(transition == 'hslide'){
                        var c = $(pages).index(currentPage);
                        var n = $(pages).index(nextPage);
                        
                        var containerW = currentPage.parent().width();
                        
                        var cM, nM;
                        
                        //alert(n + ', ' + c);
                        
                        // slide from right to left
                        if(n > c){
                            cM = -containerW;
                            nM = containerW;
                        }
                        
                        // slide from left to right
                        else{
                           cM = containerW;
                           nM = -containerW; 
                        }
                        
                        currentPage.animate({ left: cM }, transitionSpeed);
                        nextPage.css({ left: nM }).show().animate({ left: 0 }, transitionSpeed).queue(function(){
                            currentPage.hide().css({ left: 0 })
                            $(this).dequeue();
                        });
                    }
                    
                    else{
                        currentPage.hide();
                        nextPage.show();
                        
                    }
                    
                    currentPage.removeClass(currentClass);
                    nextPage.addClass(currentClass);
                
            }                     
        });
    },
    
   	$.fn.ntTabsAndSlides.defaults = {
        currentClass: 'current',
        transition: 'hsilide', // fade|hslide|vslide|none
        transitionSpeed: 'fast', // slow|fast|1000|5000 etc.
        autoSlide: false,
        slideShowDelay: 5000
	};
})(jQuery); 
