/* Plugin for Lights on Lights off - Cinema Mode */
jQuery('document').ready(function() {
    jQuery("#shadow").css("height", jQuery(document).height()).hide();
    jQuery(".lightSwitcher").click(function() {
        jQuery("#shadow").toggle();
        if (jQuery("#shadow").is(":hidden"))
            jQuery(this).removeClass("turnedOff");
        else
            jQuery(this).addClass("turnedOff");
    });

});

/* Fade in Text for Slider */
jQuery(document).ready(function() {
	jQuery(".panel img").removeAttr("alt");
    jQuery(".panel a").removeAttr("title");
    jQuery(".panel span").fadeTo("fast", 0);
    jQuery(".panel span").hover(function() {
            jQuery(this).fadeTo("normal", 0.7);

        }, function() {
            jQuery(this).fadeTo("normal", 0);
		});
});

/* RSS Button hover with color */
jQuery('document').ready(function() {
	jQuery('.loginfooter img').fadeTo("fast", 0.6); 
	jQuery('.loginfooter img').hover(function() {
	jQuery(this).fadeTo("normal", 1.0);
	jQuery(this).attr("src", jQuery(this).attr("src").replace(/.gif/, "-over.gif"));
	}, function() {
		jQuery(this).attr("src", jQuery(this).attr("src").replace(/-over.gif/, ".gif"));
		jQuery(this).fadeTo("normal", 0.6);
	});
});

/* Navigation Dropdown Menu */
jQuery('document').ready(function() {
    jQuery("#nav a").removeAttr("title");
    jQuery("#nav ul ").css({
        display: "none"
    });
    // Opera Fix
    jQuery(" #nav li").hover(function() {
        jQuery(this).find('ul:first').css({
            visibility: "visible",
            display: "none"
        }).show(300);
    }, function() {
        jQuery(this).find('ul:first').css({
            visibility: "hidden"
        });
    });
});

/* Tabs with jQuery */
jQuery('document').ready(function() {
 
	//Default Action
	jQuery(".tab_wrapper img").removeAttr("alt");
	jQuery(".tab_content").hide(); //Hide all content
	jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
	jQuery(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	jQuery("ul.tabs li").click(function() {
		jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
		jQuery(this).addClass("active"); //Add "active" class to selected tab
		jQuery(".tab_content").hide(); //Hide all tab content
		var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		jQuery(activeTab).show(); //Show the active content
		return false;
	});
 
});

/* Comment form Validation and Submission */
jQuery('document').ready(function($){
	var commentform=$('form[action$=wp-comments-post.php]');
	commentform.prepend('<div id="wdpajax-info" ></div>');
	var infodiv=$('#wdpajax-info');
	commentform.validate({
		submitHandler: function(form){
			//serialize and store form data in a variable
			var formdata=commentform.serialize();
			//Add a status message
			infodiv.html('<p>Processing...</p>');
			//Extract action URL from commentform
			var formurl=commentform.attr('action');
			//Post Form with data
			$.ajax({
				type: 'post',
				url: formurl,
				data: formdata,
				error: function(XMLHttpRequest, textStatus, errorThrown){
					infodiv.html('<p class="wdpajax-error" >You might have left one of the fields blank.</p>');
				},
				success: function(data, textStatus){
					if(data=="success")
						infodiv.html('<p class="wdpajax-success" >Thanks for your comment. We appreciate your response.</p>');
					else
						infodiv.html('<p class="wdpajax-error" >Error in processing your form.</p>');
					commentform.find('textarea[name=comment]').val('');
				}
			});
		}
	});
});
