/**
 * Start all the scripts that require initializing when jQuery is ready
 * For exclusive use with the Magnifica theme
 *
 * Author: Oscar Alcala
 * Website: http://www.themeforest.net?ref=BioXD
**/

jQuery(document).ready(function($) {
	
	// Start the sliders
	var slides = $('.slider_thumbnail').size() - 1;
	var ts_slider_speed = $('#ts_slider_speed').attr('value') * 1000;
	
	
		$('.slider_thumbnail[rel=0]').animate({
			opacity: 0.4
		}, 800);
	
	
	$('#slider').nivoSlider({
		effect: 'fold, fade',  
		animSpeed: 1200,
		pauseTime: ts_slider_speed,
		pauseOnHover: false, 
		controlNav: false, 
		directionNav: false, 
		beforeChange: function() {
			$('.current_slide').animate({
				opacity: 1 
			}, 800);
		}, 
		afterChange: function() {
			$('.slider_thumbnail[rel=' + currentSlide + ']').animate({
				opacity: 0.4 
			}, 800);
			$('.current_slide').removeClass('current_slide');
			$('.slider_thumbnail[rel=' + currentSlide + ']').addClass('current_slide');
		}
	});
	
	// Start Cufon
	Cufon.now();
	Cufon.refresh();
	
	// Start the gallery 
	$(".gallery a").attr('rel', 'gallery');
	$("a[rel^='gallery']").prettyPhoto({
				animationSpeed: 'normal', 
				opacity: 0.75, 
				showTitle: false, 
				allowresize: true, 
				counter_separator_label: '/', 
				theme: 'dark_rounded', 
				hideflash: false, 
				modal: false, 
				changepicturecallback: function(){}, 
				callback: function(){} 
			});	
			
	// Show the search box
	$("#mainmenu li").hover(function(event) {
		
		$('.sub-menu', this).slideToggle(200);
			
	});
	
	// Show the social media buttons
	facebook_button = $('#ts_social_facebook').attr('value') == 1 ? 1 : 0;
	twitter_button = $('#ts_social_twitter').attr('value') == 1 ? 1 : 0;
	digg_button = $('#ts_social_digg').attr('value') == 1 ? 1 : 0;
	
	style = $('#stylesheet_directory').attr('value');
	sdir = style + '/includes/socialmedia.php';
	$('#socialbuttons').load(sdir, { 
		'facebook': facebook_button, 'twitter' : twitter_button, 'digg' : digg_button
	});

});
