
jQuery(document).ready(function(){        

	// Home Theme Slider
    var themeSlideAmount = jQuery('#intro-theme .intro-theme-slider-link').length;
    var themeSlidePos = 0;
    var themeSlideNudge = 460;
    var themeSlideMax = themeSlideNudge * themeSlideAmount * -1;
    
    var counter = 1;
    jQuery('#intro-theme .intro-theme-slider-link').each(function(){
        jQuery(this).addClass('intro-theme-slider-link-' + counter);
        jQuery(this).css('z-index',50-counter);
        counter++;   
    });
    
	// Home Buttons
    jQuery('#intro-theme').bind('mouseenter',function(){
      jQuery('#intro-theme .intro-theme-slider-button').animate({opacity:1})
      jQuery('#intro-theme .intro-theme-slider-button-view').animate({opacity:1})
    }).bind('mouseleave',function(){
        jQuery('#intro-theme .intro-theme-slider-button').animate({opacity:0.8})
        jQuery('#intro-theme .intro-theme-slider-button-view').animate({opacity:0.8})
    });
    
	// Linkout Setup
	var linkout = jQuery('.intro-theme-slider-link-1').attr('rel');
	//alert(linkout);
	jQuery('#intro-theme .intro-theme-slider-button-view').attr('href',linkout);
	
    counter = 0;
    clicked = false;
    jQuery('#intro-theme .intro-theme-slider-button').click(function(){
       counter++;
       doSliderFade(); // Do the slider function
    });
    
    function doSliderFade(){
	  if(counter >= themeSlideAmount){   
	  jQuery('#intro-theme .intro-theme-slider-link').stop().fadeIn('slow');
	      var linkout = jQuery('.intro-theme-slider-link-1').attr('rel');
	   //alert(linkout);
	   jQuery('#intro-theme .intro-theme-slider-button-view').attr('href',linkout);
	   counter = 0; 
	   }
	   else
	   {
	       jQuery('#intro-theme .intro-theme-slider-link-' + counter).stop().fadeOut('slow');
	       var linkout = jQuery('.intro-theme-slider-link-' + (counter +1)).attr('rel');
	      // alert(linkout);
	       jQuery('#intro-theme .intro-theme-slider-button-view').attr('href',linkout);
	   } 
	}

     // Login Button
	 
    var login_box =   jQuery('#login-popout');
    var login_button = jQuery('.login-button');
    var login_button_text = login_button.html();
	login_box.css('display','none');
    jQuery('.login-button, #main .not-logged-in .whatnow .col-right .faux-login a').bind('click',function(event){
		if(login_box.css('display') == 'none'){
			  
			login_button.addClass('login-button-alternative');
			login_box.slideDown(200);
			jQuery('#login-popout input#FNAME').focus();
		  
		}
		else {
			
			login_button.removeClass('login-button-alternative');
			login_box.slideUp(200);
	
		}
	return false;
    });
    
    // Purchase popup
	jQuery('#main .single-theme .purchase .buy-theme').click(function(){
		jQuery('#main .single-theme .purchase .purchase-popup').toggle();
		if(jQuery('#overlay').length > 0){
			jQuery('#overlay').remove();
		} else {
			jQuery('body').append('<div id="overlay"></div>');
			var doc_height = jQuery(document).height();
			jQuery('#overlay').height(doc_height);
			jQuery('#overlay').click(function(){
				jQuery('#main .single-theme .purchase .purchase-popup').toggle();
				jQuery(this).remove();
			});
		}
	});

    // Sidebar Pretty...
    /*
    jQuery.easing.def = "easeInOutSine"; 
	jQuery('#sidebar .widget > ul > li').bind('mouseenter',function(){
	jQuery(this).stop().animate({
	    backgroundColor: "#E3E3E3" }, 200)
    }).bind('mouseleave',function(){
        jQuery(this).stop().animate({
            backgroundColor: "#FFFFFF" }, 500)
    });
            
	//Back to top slider
	jQuery('#toTop').click(function() {  
		jQuery('body,html').animate({scrollTop:0},800);  
	}); 
	*/
	
	// Support 
    jQuery('.support .support-block.active').fadeIn('slow');
    jQuery('.support #page-tabber li a').click(function(){
         jQuery('.support #page-tabber li.active a').parent().removeClass('active');
         jQuery(this).parent().addClass('active');

        
        var clicked = jQuery(this).attr('rel'); 
         jQuery('.support .support-block.active').fadeOut('slow', function(){ 
            jQuery(this).removeClass('active');
             jQuery('.support #support-platform-' + clicked).fadeIn('slow');
             jQuery('.support #support-platform-' + clicked).addClass('active');
         });
         
       });   
	
	// Themes page thumbnail hover effect
	//jQuery('#theme-gallery .gallery-image img').mouseover(function() {
	//	jQuery(this).stop().fadeTo(300, 0.6);
	//});
	//jQuery('#theme-gallery .gallery-image img').mouseout(function() {
	//	jQuery(this).stop().fadeTo(400, 1.0);
	//});
	
	// Themes page thumbnail hover effect
	jQuery('#theme-gallery .gallery-image a').mouseover(function() {
		jQuery(this).children('.hover').stop().fadeTo(200, 1.0);
	});
	jQuery('#theme-gallery .gallery-image a').mouseout(function() {
		jQuery(this).children('.hover').stop().fadeTo(200, 0.0);
	});
   
});

//Preloader
jQuery(window).load(
    function() {
        jQuery('#intro-theme-slides').fadeIn('slow');   // Home Page
        jQuery('.theme-screenshot-content').fadeIn('slow');    // Themes Page 
		jQuery('.intro-theme-slider-button').fadeIn('slow'); 
        jQuery('.intro-theme-slider-button-view').fadeIn('slow'); 
		jQuery('.single-theme-slider-button').fadeIn('slow');
        });
        
        
// THEME LISTING PAGE

jQuery(document).ready(function(){
    
    // Theme Demo Button
    jQuery('#theme-screenshot').bind('mouseenter',function(){
      //jQuery('#theme-screenshot .single-theme-slider-button').fadeIn('slow');
      jQuery('#theme-screenshot .single-theme-slider-button').animate({opacity:1})
    }).bind('mouseleave',function(){
        //jQuery('#theme-screenshot .single-theme-slider-button').fadeOut('slow')
        jQuery('#theme-screenshot .single-theme-slider-button').animate({opacity:0.8})
    });
    
     jQuery('table.purchase tr.show').bind('mouseenter',function(){
     //var parent = jQuery(this).next();
     jQuery(this).next().show();

    });
    jQuery('table.purchase').bind('mouseleave',function(){
     jQuery('table.purchase tr.hidden').hide();  
    
    });
    
});

// VIDEO ARCHIVE PAGE TAG SORTING

jQuery(document).ready(function(){
								
	jQuery('#main.video-page .filters a').click(function(evt){
		var clicked_cat = jQuery(this).attr('rel');
		if(clicked_cat == 'all'){
			jQuery('#video-thumbs .thumb').hide().fadeIn(200);
			jQuery('#main.video-page .filters a').parent('li').removeClass('active');
			jQuery('#main.video-page .filters a[rel="all"]').parent('li').addClass('active');
		} else {
			jQuery('#video-thumbs .thumb').hide();
			jQuery('#main.video-page .filters a').parent('li').removeClass('active');
			jQuery('#video-thumbs .' + clicked_cat).fadeIn(400);
			jQuery('#main.video-page .filters a[rel="' + clicked_cat + '"]').parent('li').addClass('active');
		 }
		//eq_heights();
		evt.preventDefault();
	});

	// Thanks @johnturner, I owe you a beer!
	var postMaxHeight = 0;
	jQuery("#video-thumbs .thumb").each(function (i) {
		 var elHeight = jQuery(this).height();
		 if(parseInt(elHeight) > postMaxHeight){
			 postMaxHeight = parseInt(elHeight);
		 }
	});
	jQuery("#video-thumbs .thumb").each(function (i) {
		jQuery(this).css('height',postMaxHeight+'px');
	});
	
	// Video archive thumb hover
	jQuery('#video-thumbs .thumb img').mouseover(function() {
		jQuery(this).stop().fadeTo(300, 0.6);
	});
	jQuery('#video-thumbs .thumb img').mouseout(function() {
		jQuery(this).stop().fadeTo(400, 1.0);
	});
	
});
