/**
 *  base
 *
 *  Created by Alex Bilstein on 2009-07-28.
 *  Copyright (c) 2009 Blue Fish Development Group. All rights reserved.
 */
 
/**
 * jQuery.placeholder - Placeholder plugin for input fields
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2008/10/14
 *
 * @author Blair Mitchelmore
 * @version 1.0.1
 *
 **/
 
new function($) {
    $.fn.placeholder = function(settings) {
        settings = settings || {};
        var key = settings.dataKey || "placeholderValue";
        var attr = settings.attr || "placeholder";
        var className = settings.className || "placeholder";
        var values = settings.values || [];
        var block = settings.blockSubmit || false;
        var blank = settings.blankSubmit || false;
        var submit = settings.onSubmit || false;
        var value = settings.value || "";
        var position = settings.cursor_position || 0;

        
        return this.filter(":input").each(function(index) { 
            $.data(this, key, values[index] || $(this).attr(attr)); 
        }).each(function() {
            if ($.trim($(this).val()) === "")
                $(this).addClass(className).val($.data(this, key));
        }).focus(function() {
            if ($.trim($(this).val()) === $.data(this, key)) 
                $(this).removeClass(className).val(value)
                if ($.fn.setCursorPosition) {
                  $(this).setCursorPosition(position);
                }
        }).blur(function() {
            if ($.trim($(this).val()) === value)
                $(this).addClass(className).val($.data(this, key));
        }).each(function(index, elem) {
            if (block)
                new function(e) {
                    $(e.form).submit(function() {
                        return $.trim($(e).val()) != $.data(e, key)
                    });
                }(elem);
            else if (blank)
                new function(e) {
                    $(e.form).submit(function() {
                        if ($.trim($(e).val()) == $.data(e, key)) 
                            $(e).removeClass(className).val("");
                        return true;
                    });
                }(elem);
            else if (submit)
                new function(e) { $(e.form).submit(submit); }(elem);
        });
    };
}(jQuery);

/* Function:    vAlign
* Description: vertically align a block level element inside another  
* Parameters:  none
* Returns:     null
*/
(function($) {
    $.fn.valign = function() {
        return this.each(function(i) {
            var ah = $(this).height();
            var ph = $(this).parent().height();
            var mh = (ph - ah) / 2;
            $(this).css('margin-top', mh);
        });
    };
})(jQuery);

/**
 * Equalize Columns
 * Equalizes the heights of all elements in a jQuery collection.
 * usage: $("#col1, #col2, #col3").equalizeCols();
 */

(function($) {
	 
	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie ? "1%" : "auto";
  
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);

/**
 *
 * JQuery Document Ready
 * Functions to be executed when the DOM is ready.
 */

$(document).ready(function () {
    
    /* home page rollover areas */
    $(".teach").hover(function() {
        $(".teach-highlight").fadeTo("slow", 1.0); // This sets the opacity to 100% on hover
    },function(){
       	$(".thumbs img").fadeTo("slow", 0.6); // This sets the opacity back to 60% on mouseout
    });
    
    /* search input placeholder text */
    $("#search").placeholder({blankSubmit: true}); 
    
    /* equalize column heights */
    $("#column-1, #column-2, #column-3").equalizeCols(); 
    
    /* toggle the menu items */
    $("li.category > span.toggle").click(function(){
        $(this).siblings("ul").slideToggle("fast");
        var parent = $(this).parent().get(0);
        $(parent).toggleClass("open");
        $(this).toggleClass("open");
    });
    
    /* toggle login form */
    $("h3.login-toggle").click(function(){
        $(this).siblings("div.login.express").slideToggle("fast");
        $(this).toggleClass("open");
        return false;
    });
    
    /* form validation */
    $("#add-library-content").validate();
    
    /* rich text editor */
    $('textarea.tinymce').tinymce({
        
        // Location of TinyMCE script
        script_url : '/includes/tiny_mce/tiny_mce.js',
       
        // options
        mode: "textareas",
    	theme: "advanced",
    	skin: "tun",
        width: "98%",
    	height: "164",
    	theme_advanced_toolbar_location : "top",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,link",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : ""

	});

	$(".valign").valign();
});


