$(function() {
    // small slider
    $("#jFlow-controller").jFlow({
        slides: "#slides",
        width: "99%",
        duration: 400
    });
	
    var timeInterval = 7000;
    var interval = setInterval(slide, timeInterval);
    function slide() {
        $('img.jFlowNext').trigger('click');
    }
	
    $("img.jFlowNext, img.jFlowPrev").click(function() {
        clearInterval(interval);
        interval = setInterval(slide, timeInterval);
    });
	
    // Login cription
    $('form input[type="submit"]').click(function() {
        $('img.ajax_loader').show();
    })
    $('form').jCryption({
        getKeysURL : $('form input[type="submit"]').attr('title'),
        postVariable : 'data'
    });
	
    // scrrol window when login fails
    if(location.href.split('/').pop() == 'login') {
        window.scroll(0,700);
    }

    // show boxes
    $('div.wrap-p a.more').removeAttr('style');
    $('div.wrap-p div.second').hide();
    $('div.tile').css({
        'height': '250px'
    });
    $("div#main_top").css({
        'height': '253px'
    });
    $("div#main_top a.more").toggle(function() {
        var showLink = $(this);
        showLink.hide();
        var bodyHeight = $('body').outerHeight();
        
        $('body').append($('<div class="tile-bg" style="position: absolute; top: 0; left: 0; width: 100%; height: '
            + bodyHeight + 'px; ' +
            'background-image: url(public/img/tile_bg.png); z-index: 10;">'));
        $tile =  showLink.parent('div').parent('div');
        $tile.css({
            'z-index': '100'
        })
        var secondDiv = showLink.siblings('.second');
        var secondDivHeight = secondDiv.outerHeight();
        secondDiv.show();
        $tile.animate({
            height : "+=" + secondDivHeight + "px"
            }, function() {
                showLink.removeClass('more').addClass('close').show();
            });
        if (jQuery.browser.msie && $.browser.version == '7.0') {
            
            var height = $tile.parent('div').outerHeight();
            $tile.parent('div').append($('<div class="tile-bg" style="position: absolute; top: 0; left: 0; width: 100%; height: '+height +
                ';background-image: url(public/img/tile_bg.png); z-index: 20;">'));
        }


        return false;
    },	function () {
        $('div.wrap-p div.second').hide();
        var $hideLink = $(this);
        $hideLink.hide();
        var secondDiv = $(this).siblings('.second');
        var secondDivHeight = secondDiv.outerHeight();
        secondDiv.hide();
        
        $hideLink.parent('div').parent('div').animate({
            height : "-=" + secondDivHeight + "px"
            },
        function(){
            secondDiv.hide();

            $(this).css('z-index', '8');
            
            $('div.tile-bg').fadeOut(100, function() {
                $(this).remove();
                $hideLink.removeClass('close').addClass('more').show();
            });
            
        });
        return false;
    });
})