
Function.prototype.bind = function() {
  var fn = this, args = jQuery.makeArray(arguments), scope = args.shift();
  return function() {
    return fn.apply(scope, args);
  }
}

var Slider = {
  
  links: [],
  posts: [],
  current: -1,
  options: { duration: 5000, autoStart: true },
	
  init: function(posts, links, options) {
  
		this.links = jQuery(links); //  $('div.featured_nav ul li')
		this.posts = jQuery(posts);
		this.options = jQuery.extend(this.options, options || {});
		
		var ref = this;
		this.links.each(function(index) {
      jQuery(this).children('a').mouseover(ref.show.bind(ref, index));
		});

		this.show(0, false);

		if(this.options.autoStart) {
  		this.timer = setInterval(this.next.bind(this), this.options.duration);
		}

  },
  
  show: function(index, pause) {
     if(this.current == index) return;

     this.hideCurrent();
    
    this.current = index;
    var link = jQuery(this.links[this.current]);
    var post = jQuery(this.posts[this.current]);
  
    link.addClass('active');
    post.fadeIn('slow');
	
  	if(pause != false) {
			clearTimeout(this.timer);
	}
	
	return false;
	
  },

  next: function() {
		var nextIndex = parseInt(this.current + 1);
	    
		if(nextIndex >= jQuery(this.posts).length) {
		  nextIndex = 0;
		}
		
		this.show(nextIndex, false);
	},
	
  hideCurrent: function() {

    if(this.current >= 0 && this.current <= this.posts.length) {
      var link = jQuery(this.links[this.current]);
      var post = jQuery(this.posts[this.current]);
      
      link.removeClass('active');
      post.fadeOut();
    }
    
  }

};

/*******
*
*	Ticker for Related and Popular Contents
*
******/
var Class = function(d) { var c = function() { this.initialize.apply(this, arguments) }; for(var i in d) c.prototype[i] = d[i]; return c };

var Ticker = new Class({
  height:  null,
  current: 0,
  timer:   null,

  initialize: function(selector) {
    this.element = jQuery(selector);
    this.height  = this.element.height();
  },
  
  next: function(pause) {
    var child = this.element.children();
    var top   = parseInt(child.css('top')) || 0;
    
    if(top - this.height <= child.height() * -1)
      top = this.height;

    child.animate({'top': top - this.height}, {'duration': 1100, 'easing': 'swing'});
    
    if(pause) clearInterval(this.timer);
  },
  
  prev: function(pause) {
    var child = this.element.children();
    var top   = parseInt(child.css('top')) || 0;
        
    if(top >= 0)
      top = child.height() * -1;
    
    child.animate({'top': top + this.height}, {'duration': 1100, 'easing': 'swing'});
    
    if(pause) clearInterval(this.timer);
  },
  
  start: function() {
    this.timer = setInterval(this.next.bind(this), 7000);
  }

});


jQuery.fn.dropDown = function() {
  return this.each(function() {
	
	  jQuery(this).children('li').each(function(i) {
		  var item = jQuery(this);
		  if(item.hasClass('active')) {
			  item.parent().css('top', -1 * i * 24);
			
			  item.click(function() {
			    if(item.parent().hasClass('open')) {
			      jQuery(document).trigger('click');
			      return;
			    }
			    
				  jQuery(this).parent().children('li').not('li.active').css('visibility', 'visible');
				  //jQuery(this).parent().children('li.active').addClass('opened');
				  jQuery(this).parent().addClass('open');
			  });
			
		  } else {
			  item.css('visibility', 'hidden');
		  }
	  });
		
	  jQuery(this).parent().click(function(e) {
		  e.stopPropagation();
	  });
		
	  var ref = jQuery(this);

	  jQuery(document).click(function() {
		  ref.children('li').not('li.active').css('visibility', 'hidden');
		  ref.removeClass('open');
	  });
	
  	jQuery(this).trigger('mouseleave');
  	
  });
};

(function($) {
  $.fn.poorTabs = function() {
    var items = this;
  
    this.each(function() {
      this.hash = this.href.substring(this.href.indexOf('#'));
      
      $(this).click(function() {
        items.not(this.hash).each(function() { $(this.hash).hide(); $(this).removeClass('selected'); });
        $(this.hash).show(); 
        $(this).addClass('selected');
        return false;
      });

    });
  
  }
})(jQuery);

if($.browser.msie) {
  $(document).ready(function() {
    $('.cf').append('<div class="cfake"></div>');
  });
}


function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

