﻿$(document).ready(function() {
    //var so = new SWFObject("Flash/Banner.swf", "banner", "964", "387", "7", "#FFFFFF");
    //so.addParam("wmode", "transparent");
    //so.write("divflash");

    var arrorLeft = $('.arror-left');
    var arrorRight = $('.arror-right');

    var lstPic = $('.div-single-pic');
    var index = 0;
    var max = lstPic.length - 1;
    var indexDiv = lstPic.eq(index);

    var locked = false;
    var effect = "";
    arrorLeft.bind('click', function(n) {
        if (!locked) {
            locked = true;
            effect = GetRandomEffect();
            lstPic.eq(index).hide(effect, { direction: "horizontal" }, 2000, null);
            index--
            if (index < 0) index = max;
            lstPic.eq(index).show(effect, null, 2000, null);
            setTimeout(function() {
                locked = false;
            }, 2000);
            //$('#div-test').append(random+" ")
        }
    })
    arrorRight.bind('click', function(n) {
        if (!locked) {
            locked = true;
            effect = GetRandomEffect();
            lstPic.eq(index).hide(effect, { direction: "horizontal" }, 2000, null);
            index++;
            if (index > max) index = 0;
            lstPic.eq(index).show(effect, { direction: "horizontal" }, 2000, null);
            setTimeout(function() {
                locked = false;
            }, 2000);
        }
    })

    var stoped = false;
    $('#div-inner-banner').bind('mouseover', function(n) {
        stoped = true;
    })
    $('#div-inner-banner').bind('mouseout', function(n) {
        stoped = false;
    })

    function AutoChangeBanner() {
        setTimeout(function() {
            if (!stoped) {
                arrorRight.trigger('click');
                AutoChangeBanner();
            }            
        }, 5000);
    }
    AutoChangeBanner();

    var random = 0;
    function GetRandomEffect() {
        random = Math.floor(Math.random() * 40) % 4
        switch (random) {
            case 0:
                return "slide";
                break;
            case 1:
                return "blind";
                break;
            case 2:
                return "fold";
                break;
            case 3:
                return "clip";
                break;
            default:
                return "blind";
                break;
        }
    }

//    if ($.browser.msie && $.browser.version <= 6) {
//        $('.div-single-pic').show();
//        $.each($('img'), function (i, n) {
//            fixPNG(this);
//        })
//        $('.div-single-pic').hide();
//        $('.div-single-pic:eq(0)').show();  
//    }
})      
