/*
	Easy plugin to get element index position
	Author: Peerapong Pulpipatnan
	http://themeforest.net/user/peerapong
*/

$.fn.getIndex = function(){
	var $p=$(this).parent().children();
    return $p.index(this);
}

$.fn.setNav = function(){
	jQuery('#main_menu li ul').css({display: 'none'});

	jQuery('#main_menu li').each(function()
	{	
		
		var $sublist = jQuery(this).find('ul:first');
		
		jQuery(this).hover(function()
		{	
			$sublist.stop().css({overflow:'hidden', height:'auto', display:'none'}).slideDown(200, function()
			{
				jQuery(this).css({overflow:'visible', height:'auto'});
			});	
		},
		function()
		{	
			$sublist.stop().slideUp(200, function()
			{	
				jQuery(this).css({overflow:'hidden', display:'none'});
			});
		});	
		
		jQuery(this).click(function()
		{
			$(this).children('a').click();
		});
	});
}

$.fn.pSlider = function(options){
	
	settings = jQuery.extend({
     	nav: '#slider_nav',
     	navWrapper: '.slider_nav_btn',
     	fadeSpeed: 800,
     	delay: 5000
  	}, options);
	
	var slideWrapper = $(this);
	var slideNav = settings.nav+' '+settings.navWrapper;
	
	$(this).children('div').css({ 'display': 'none' });
	
	var i = 0;
	$(this).children('div').each(function(){
		
		if($(this).attr('id') != 'slider_nav')
		{
			var slideTitle = $(this).children('span.title').html();
			$(slideNav).append('<a href="javascript:;" rel="'+i+'">'+slideTitle+'</a>');
			
			if($(this).children('span.title').children('img').length > 0)
			{
				$(slideNav).children('a[rel='+i+']').css({ 'padding': '6px 15px 0px 15px' });
			}
			
			i++;
		}
	});
	
	$(slideNav).children('a').eq(0).addClass('active');
	$(this).children('div').eq(0).css({ 'display': 'block' });
	
	var it = setInterval(function(){
     	
     	if($(slideNav+' a.active').next().length > 0)
     	{
     		
     		var nextSlide = $(slideNav+' a.active').next();
     		var slideTarget = $(slideNav+' a.active').next().attr('rel');
		
			// Remove all active slide
			slideWrapper.children('div').css({ 'display': 'none' });
			
			if(BrowserDetect.browser != 'Explorer')
			{
				slideWrapper.children('div').eq(slideTarget).fadeIn(settings.fadeSpeed);
			}
			else
			{
				slideWrapper.children('div').eq(slideTarget).css({ 'display': 'block' });
			}
			
			$(settings.nav+' a').removeClass('active');
			nextSlide.addClass('active');
     		
     	}
     	else
     	{
     	
     		// Remove all active slide
			slideWrapper.children('div').css({ 'display': 'none' });
			
			if(BrowserDetect.browser != 'Explorer')
			{
				slideWrapper.children('div').eq(0).fadeIn(settings.fadeSpeed);
			}
			else
			{
				slideWrapper.children('div').eq(0).css({ 'display': 'block' });
			}
			
			$(settings.nav+' a').removeClass('active');
			$(settings.nav+' a').eq(0).addClass('active');

     	}
     	 
    }, settings.delay);
    $(slideNav+' a').click(function(){
	
		$(settings.nav+' a').removeClass('active');
		$(this).addClass('active');
		
		var targetSlide = $(this).attr('rel');
		
		slideWrapper.children('div').css({ 'display': 'none' });
		
		if(BrowserDetect.browser != 'Explorer')
		{
			slideWrapper.children('div').eq(targetSlide).fadeIn(settings.fadeSpeed);
		}
		else
		{
			slideWrapper.children('div').eq(targetSlide).css({ 'display': 'block' });
		}
		
		clearInterval(it);
	
		return false;
	});
	
	$(slideNav).children('a').eq(0).addClass('active');
	$(this).children('div').eq(0).css({ 'display': 'block' });
	
}
   jQuery.noConflict();
   
jQuery(document).ready(function(){ 

	jQuery(document).setNav();
	

});
