 /*-----------------------------------------------
'	Company: Community Engine (www.communityengine.com)
'	Copyright (c) 2010, All rights reserved.
'	Date Created: April 2010
'
'	Last Modified Date: 21st April, 2010
'	Last Modified By: Benjamin -> ben.ruhe@communityengine.com
'
'	DO NOT MODIFY THIS DOCUMENT WITHOUT
'	NOTIFYING THE AUTHOR FIRST
'
------------------------------------------------*/
var $j = jQuery.noConflict();
// Kentico media library affects jQuery so use $j NOT $


$j(function () {

    $j('.module-carousel').nivoSlider({
        effect: 'fade',
        animSpeed: 800,
        pauseTime: 7000,
        slices: 1,
        directionNav: false
    });

    $j.fn.defaultVal = function () {
        return this.focus(function () {
            if (this.value == this.defaultValue) {
                this.value = "";
            }
        }).blur(function () {
            if (!this.value.length) {
                this.value = this.defaultValue;
            }
        });
    };
    $j(".defaultVal").defaultVal();

    $j("ul.top-nav").supersubs({
        maxWidth: 40,
        extraWidth: 1
    }).superfish({
        hoverClass: "hover",
        animation: { opacity: 'show', height: 'show' },
        delay: 0,
        autoArrows: false
    }); 

    function ShowValueLength(srcEl) {
        var charLength = $j(srcEl).val().length;
        var charCount = $j(srcEl).closest('li').find('.charCount');
        var maxChars = $j(srcEl).closest('li').find('.maxChars').text();
        $j(charCount).html(charLength);
        if (charLength > maxChars) {
            $j(charCount).html('<strong>You have exceeded the maximum </strong>');
            if (charCount.hasClass('enforce'))
                srcEl.value = srcEl.value.substring(0, maxChars)
        }
    }

    $j('.featured-campaign li').equalCols();


    // controls character input/counter
    $j('textarea.countChars').each(function () {
        ShowValueLength(this);
    });
    $j('textarea.countChars').keyup(function () {
        ShowValueLength(this);
    });

    // End Function
});



//Funtion to init Jquery Form Select Option Dropdown
function jqueryDropDownInit(dropdownOption){
    $j(document).ready(function() {
        $j("." + dropdownOption + " img.flag").addClass("flagvisibility");

        $j("." + dropdownOption + " dt a").click(function() {
        $j("." + dropdownOption + " dd ul").toggle(); 
            return false;
        });

        $j("." + dropdownOption + " dd ul li a").click(function() {
            var text = $j(this).html();
            $j("." + dropdownOption + " dt a span").html(text);
            $j("." + dropdownOption + " dd ul").hide();
        });

        function getSelectedValue(id) {
            return $j("#" + id).find("dt a span.value").html();
        }

        $j(document).bind('click', function(e) {
            var $clicked = $j(e.target);
            if (!$clicked.parents().hasClass(dropdownOption)) {
                $j("." + dropdownOption + " dd ul").hide();
            }
        });


        $j("#flagSwitcher").click(function() {
            $j("." + dropdownOption + " img.flag").toggleClass("flagvisibility");
        });
    });
}

//Funtion to set value to form element by ID
function setFormValue(formID,inputValue){
	document.getElementById(formID).value = inputValue;
}

jQuery.fn.equalCols = function () {
    var sortNumber = function (a, b) { return b - a; };
    var heights = [];
    $j(this).each(function () {
        heights.push($j(this).height());
    });
    heights.sort(sortNumber);
    var maxHeight = heights[0];
    return this.each(function () {
        $j(this).css({ 'min-height': maxHeight }); // Do a fix for IE
        if ($j.browser.msie && $j.browser.version == "6.0") {
            $j(this).css({ 'height': maxHeight }); // Do a fix for IE6
        }
        //	console.log(maxHeight);
    });
};
