jQuery(document).ready(function(){


	// EQUAL HEIGHT POST DIVS
	var $equalHeightDivs = jQuery('.equal-height #content > .post');
    var maxHeight = 0;
    $equalHeightDivs.each(function() {
        maxHeight = Math.max(maxHeight, jQuery(this).outerHeight());
    });
    $equalHeightDivs.css({ height: maxHeight-35 + 'px' });


	// ADD WRAP TO TAG CLOUD TAGS IN FOOTER
	jQuery('#footer .widget_tag_cloud a').wrap('<div class="tag" />');


	// DROPDOWN MENU WITH FADE
	jQuery(".dropdown ul,.slide-menu .slide").each(
	function (i) { // Preserves the mouse-over on top-level menu elements when hovering over children
	    jQuery(this).hover(
	    function () {
	        jQuery(this).parent().find("a").slice(0, 1).addClass("active");
	    }, function () {
	        jQuery(this).parent().find("a").slice(0, 1).removeClass("active");
	    });
	});
	jQuery(".dropdown ul").parent().find("a:first").append("<span class='darr'>&nbsp;&nbsp;&darr;</span><span class='rarr'>&nbsp;&nbsp;&rarr;</span>").addClass("parent");
	jQuery(".fadein ul").css({
	    display: "none"
	}); // Opera Fix
	jQuery(".fadein li").hover(
	function () {
	    jQuery("ul:first", this).css({
	        visibility: "visible",
	        display: "none"
	    }).fadeIn(400);
	}, function () {
	    jQuery("ul:first", this).css({
	        visibility: "hidden"
	    });
	});
	jQuery(this).find(".sub").stop().fadeTo('fast', 1).show();
	if (jQuery.browser.msie && (jQuery.browser.version < 7)) { // IE6 Fix: Drop-down fix due to lack of support for :hover on list elements
	    jQuery(".dropdown").each(
	    function (i) {
	        jQuery("li", this).hover(
	        function () {
	            jQuery(this).addClass("ie6hover");
	        }, function () {
	            jQuery(this).removeClass("ie6hover");
	        });
	    });
	}


	// SLIDEDOWN MENU
	jQuery(".slide-menu li").hover(
	function () {
	    jQuery("ul", this).stop("true", "true").slideDown("slow");
	}, function () {
	    jQuery("ul", this).slideUp();
	});


	// SLIDE TOGGLE (an anchor tag with class '.toggle' will expand it's href target)
	jQuery('.toggle').bind('click', function() {
		var maketoggle = jQuery(this).attr('href');
		jQuery(maketoggle).slideToggle(300);
		return false;
	});


	// SMOOTH SCROLL
	jQuery('a[href*=#]').click(function () {
	    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
	        var $target = jQuery(this.hash);
	        $target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) + ']');
	        if ($target.length) {
	            var targetOffset = $target.offset().top;
	            jQuery('html,body').animate({
	                scrollTop: targetOffset
	            }, 700);
	            return false;
	        }
	    }
	});


	// TABBER WIDGET
	var list = '<ul class="tabs cf">';
	jQuery('.tabber').find('h3.widget-title').each(function () {
	    var the_title = jQuery(this).html();
	    list += '<li><a href="#">' + the_title + '</a></li>';
	});
	list += '</ul>';
	jQuery('.tabber').prepend(list);
	jQuery(".tabber .tabs").tabs(".tabber .widget", { // requires jquerytools.js
	    effect: 'fade'
	});


//	// EQUAL HIEGHT #CONTENT AND #SIDEBAR COLUMS
//	if(jQuery('#sidebar').height() > jQuery('#content').height()) {
//		jQuery('#content').height(jQuery('#sidebar').height());
//	}
//	else {
//		jQuery('#sidebar').height(jQuery('#content').height());
//	}



	// RANDOMIZE PLUGIN
    jQuery.fn.randomize = function (childElem) {
        return this.each(function () {
            var jQuerythis = jQuery(this);
            var elems = jQuerythis.find(childElem);
            elems.sort(function () {
                return (Math.round(Math.random()) - 0.5);
            });
            jQuerythis.remove(childElem);
            for (var i = 0; i < elems.length; i++)
            jQuerythis.append(elems[i]);
        });
    }

	//RANDOMIZE (ADS)
    jQuery(".ads-inside.random").randomize("a");


	// CONTACT FORM
	jQuery.fn.exists = function () { // Check if element exists
	    return jQuery(this).length;
	}
	jQuery('.dt-contactform').submit(function () {
	    var cf = jQuery(this);
	    cf.prev('.alert').slideUp(400, function () {
	        cf.prev('.alert').hide();
	        cf.find('.submit').after('').attr('disabled', 'disabled');
	        jQuery.post(ajaxurl, {
	            name: cf.find('.dt-name').val(),
	            email: cf.find('.dt-email').val(),
	            subject: cf.find('.dt-subject').val(),
	            comments: cf.find('.dt-comments').val(),
	            verify: cf.find('.dt-verify').val(),
	            action: 'dt_contact_form'
	        }, function (data) {
	            cf.prev('.alert').html(data);
	            cf.prev('.alert').slideDown('slow');
	            cf.find('img.loader').fadeOut('slow', function () {
	                jQuery(this).remove()
	            });
	            cf.find('.submit').attr('disabled', '');
	            if (data.match('success') != null) cf.slideUp('slow');
	        });
	    });
	    return false;
	});


});
