$(document).ready(function(){

    // --------------------------------------------------------------------------------------------------
    // ---- set column heights --------------------------------------------------------------------------
    // --------------------------------------------------------------------------------------------------

    // content columns
    var highestCol = Math.max($('#main_column_right_wrapper').height(),$('#main_column_left_wrapper').height(), $('#leftmenu_wraper').height());
    $('#main_column_right_wrapper, #main_column_left_wrapper, #leftmenu_wraper').height(highestCol);

    // inner content columns
    $('.innercontentblock').each(function(){
        $(this).height($(this).parent().height());
    });

    // --------------------------------------------------------------------------------------------------
    // ---- init accordion menu -------------------------------------------------------------------------
    // ---- http://www.designchemical.com/lab/jquery-vertical-accordion-menu-plugin/ --------------------
    // --------------------------------------------------------------------------------------------------

    $('#accordion-left').dcAccordion({
        classParent  : 'dcjq-parent',    //Class of parent menu item
        classActive  : 'active',    // Class of active parent link
        classArrow   : 'dcjq-icon',    // Class of span tag for parent arrows
        classCount   : 'dcjq-count',    // Class of span tag containing count (if addCount: true)
        classExpand : 'dcjq-current-parent',    // Class of parent li tag for auto-expand option
        eventType: 'click',
        autoClose: true,
        autoExpand   : false,
        saveState: true,
        cookie	: 'vk-accordion',
        disableLink: false,
        speed: 300,
        showCount: false
    });

    // --------------------------------------------------------------------------------------------------
    // ---- init rotators -------------------------------------------------------------------------------
    // --------------------------------------------------------------------------------------------------


    $("#widget_news_rotator").carouFredSel({
	width: 410,
	align: "left",
	height: 390,
	items: {
		visible: 1,
		minimum: 1,
		width: 410,
		height: 390
	},
	scroll: {
                items: 1,
		easing: "easeInOutSine",
		duration: 500,
		pauseOnHover: true
	},
	auto: {
		pauseDuration: 5000,
		delay: 1000
	},
	pagination: "#widget_news_pagination",
	prev: "#widget_news_back",
	next: "#widget_news_next"
    });

    $("#widget_banner_middlecolumn_full_rotator").carouFredSel({
	width: 410,
	align: "left",
	height: 145,
	items: {
                start: "random",
		visible: 1,
		minimum: 1,
		width: 410,
		height: 145
	},
	scroll: {
                items: 1,
		easing: "easeInOutSine",
		duration: 500,
		pauseOnHover: true,
                onBefore: function( oldItems, newItems, newSizes ) {
			//console.log('log banner view: '+$(oldItems).attr('rel'));
		}
	},
	auto: {
		pauseDuration: 3000,
		delay: 1000
	},
	pagination: "#widget_banner_middlecolumn_full_pagination",
	prev: "#widget_banner_middlecolumn_full_back",
	next: "#widget_banner_middlecolumn_full_next"
    });
    
    $("#widget_banner_middlecolumn_half_rotator").carouFredSel({
	width: 190,
	align: "left",
	height: 400,
	items: {
                start: "random",
		visible: 1,
		minimum: 1,
		width: 190,
		height: 400
	},
	scroll: {
                fx: "fade",
                items: 1,
		easing: "easeInOutSine",
		duration: 500,
		pauseOnHover: true,
                onBefore: function( oldItems, newItems, newSizes ) {
			//console.log('log banner view: '+$(oldItems).attr('rel'));
		}
	},
	auto: {
		pauseDuration: 3000,
		delay: 1000
	},
	pagination: "#widget_banner_middlecolumn_half_pagination",
	prev: "#widget_banner_middlecolumn_half_back",
	next: "#widget_banner_middlecolumn_half_next"
    });

    $("#widget_banner_rightcolumn_full_rotator").carouFredSel({
	width: 340,
	align: "left",
	height: 195,
	items: {
                start: "random",
		visible: 1,
		minimum: 1,
		width: 340,
		height: 195
	},
	scroll: {
                fx: "fade",
                items: 1,
		easing: "easeInOutSine",
		duration: 500,
		pauseOnHover: true,
                onBefore: function( oldItems, newItems, newSizes ) {
			//console.log('log banner view: '+$(oldItems).attr('rel'));
		}
	},
	auto: {
		pauseDuration: 3000,
		delay: 1000
	},
	pagination: "#widget_banner_rightcolumn_full_pagination",
	prev: "#widget_banner_rightcolumn_full_back",
	next: "#widget_banner_rightcolumn_full_next"
    });

    // count down
    var countdown;
    var countdown_number;

    function countdown_init() {
        countdown_number = 5;
        countdown_trigger();
    }

    function countdown_trigger() {
        if(countdown_number > 0) {
            countdown_number--;
            $('.countdown_text').html(countdown_number);
            console.log(countdown_number);
            if(countdown_number > 0) {
                countdown = setTimeout(countdown_trigger, 1000);
            }else if(countdown_number <=0 ){
                location.reload();
            }
        }
    }

    // reactions form
    $('#reaction_form_message').hide();
    $('#reactionform').submit(function(){

            var action = $(this).attr('action');

            $("#reaction_form_message").slideUp(200,function() {
                $('#submit')
                        .addClass('submitloader')
                        .attr('disabled','disabled');

                $.post(action, {
                        name: $('#name').val(),
                        email: $('#email').val(),
                        comments: $('#comments').val(),
                        verify: $('#verify').val(),
                        artid:  $('#art_id').val(),
                        s1: $('#s1').val(),
                        s2: $('#s2').val(),
                        h: $('#h').val()

                },
                        function(data){
                                document.getElementById('reaction_form_message').innerHTML = data;
                                $('#reaction_form_message').slideDown(200);
                                $('#reactionform img.loader').fadeOut(200,function(){$(this).remove()});
                                $('#submit').removeAttr('disabled');
                                $('#submit').removeClass('submitloader');
                                if(data.match('success') != null){
                                    $('#reactionform').slideUp(200);
                                    countdown_init();
                                }
                        }
                );

            });

            return false;

    });

    // reactions coloring
    $("#allreactions div:even").css("background-color", "#e7e7e7");
    $("#allreactions div:odd").css("background-color", "#f5f5f5");


});
