var default_date = new Date();
var max_date = new Date();

$(document).ready(function() {

    $('.items_row').each(function(index) {
        var eh =$(".even", this).height();
        var oh =$(".odd", this).height();
        if (eh > oh){
            $(".odd", this).css('height', eh);
        }
        else {
            if (eh){
                $(".even", this).css('height', oh);
            }
        }
    });


    $( "#calendar" ).datepicker({
        minDate : new Date(),
        maxDate : max_date,
        defaultDate : default_date,
        
        beforeShowDay: function(date){
            if (jQuery.inArray(date.toString(), a_dates) > -1){
                if (active_date == date.toString()){
                return [1, 'active_date selected'];
                }
                return [1, 'active_date'];
            }
            else{
                return [0, ''];
            }
        },

        onChangeMonthYear: function(year, month, inst) {
            if (rm == 1){
           window.location = r_url + ',date.'+ year + '-' + month;
            }
        },
        
        onSelect: function(dateText, inst) {
            window.location = r_url + ',date.'+ dateText;
        }
    });


    $( "#calendar" ).datepicker({
        showOtherMonths: true
    });

    $( "nav li ul" ).each(function () {
	var w1 = $(this).parent().width();
    var w2 = $(this).width();
	if (w2 > w1){
	$('a', $(this).parent()).width(w2);
	}
	else{
    $(this).width($(this).parent().width());
	}
    });

    $( "nav li" ).each(function () {
        $(this).mouseover(function() {
            $(this).addClass("hover");
        });
        $(this).mouseout(function() {
            $(this).removeClass("hover");
        });
    });


if (window.PIE) {
     $('nav > ul > li > a, .search input[type="text"], .counter_wrapper, .search input[type="submit"], .structure-block header, .calendar-page .list-item, .title .tag, .structure-block, .structure-block-content, .performance-list-item, #calendar, .contacts-form, .newsletter input[type="text"], input[type="submit"], .more, .custom-red-button, #header .menu ul').each(function() {
       PIE.attach(this);
     });
   }
   
});


function changePhoto(src, src_large){
    $('.main-image').html('<a title="" href="'+src_large+'" class="main image_link" rel="group1"><img src="'+src+'" alt="" /></a>');
    $("a.image_link").fancybox({'showNavArrows' : true, 'titleShow' : false});
}

var poll = {

    vote: function( parent, question_id, form ){

        if (!$(form).find('input[name=polls]:checked').length) {
            $(form).find('.error-message').show();
            return false;
        }
        var answer_id = $(form).find('input[name=polls]:checked').val();
        $.post( poll_ajax_href + ',poll_results.1', {
            "question_id": question_id,
            "action": "vote",
            "polls": answer_id
        }, function( data ){
            $('#' + parent).html(data);
        });
        return false;
    },

    loadResults: function( parent ){
        $('#' + parent).html('<div class="ajax_preloader">&nbsp;</div>');
        $('#' + parent).load( poll_ajax_href + ',poll_results.1' );
    }

};
