﻿$(document).ready(function () {

    $(function () {
        var galleries = $('.ad-gallery').adGallery();
        $('#switch-effect').change(
            function () {
                galleries[0].settings.effect = $(this).val();
                return false;
            }
                        );
    });

    $("#pageflip").hover(function () {
        $("#pageflip img , .msg_block").stop()
			    .animate({
			        width: '307px',
			        height: '319px'
			    }, 500);
    }, function () {
        $("#pageflip img").stop()
			    .animate({
			        width: '65px',
			        height: '67px'
			    }, 220);
        $(".msg_block").stop()
			    .animate({
			        width: '65px',
			        height: '65px'
			    }, 200);
			});

		divCount = 0;
		$('.offers > div').each(function () { divCount++; });
		if (divCount > 1) { setInterval('currentofferSwitch()', 5000); }


});

function currentofferSwitch() {

    var $old = null;
    var $next = null;

    $('.offers > div').each(function () {

        if ($old != null && $next == null) {

            $next = $(this);
        }

        if ($(this).attr('class') == 'active') {

            $old = $(this);
        }
    });

    if ($next == null) {

        $next = $('.offers > div:first');
    }

    if ($old == null || $next == null) {
        return;
    }

    $next.fadeIn(1500, function () { $next.removeClass('inactive').addClass('active'); });
    $old.fadeOut(1500, function () { $old.removeClass('active').addClass('inactive'); });
}
