﻿//jQuery(window).bind("load", function() {
//    //jQuery("#home-flash").codaSlider();
//    // jQuery("div#slider2").codaSlider()
//    // etc, etc. Beware of cross-linking difficulties if using multiple sliders on one page.

//    /* hide all other then first */ 
//    $("div#home-flash .panel:not(:first)").hide();

//});

/* CONSTS */
var blockUIPageMessage = '<div class=\"loading\"><img src=/themes/standart/images/loading-large.gif />Please wait...</div>';


/*
    handle if escape button clicked! if so unblockUI if its blocked!
*/
$(document).keyup(function(e) {
    window.status = e.keyCode;
    if (e.keyCode == 27) {
        try { $.unblockUI(); }
        catch (e) { window.status = e.message; }
    }
})

/* images */
var bgs = new Array('bg1', 'bg2', 'bg3');

/* settings */
var interval = 4500; // this value should be at least as twice as bigger then fadespeed value!
var fadeSpeed = 700;
var opacity = 0;

var obj1, obj2;
var ii = 1;
function __changebackground() {
    //$('body').hide('slow');
    //$('#bg').css('background', 'red');
    //$('#bg').addClass('bg1');
    
    obj1.fadeTo(fadeSpeed
                    , opacity, function() {
                        obj2.attr('class', bgs[ii % bgs.length]);                        
                    }
    );

    obj2.fadeTo(fadeSpeed, 1);
    
    
    ii++;

    // swap objects
    if ($(obj1).attr('id') == 'bgg2') { obj1 = $('#bgg'); obj2 = $('#bgg2'); }
    else { obj1 = $('#bgg2'); obj2 = $('#bgg'); }

}



/************************************************************************************
    Dom is ready to use.
************************************************************************************/
$(document).ready(function() {

    // change bg with animation.
    // setTimeout(function() { alert('ss'); }, 1000);




    obj1 = $('#bgg2'); obj2 = $('#bgg');


    /*setInterval(__changebackground, interval);
    setInterval(function() {
    $('#bgg').css('min-height', '100%');
    $('#bgg2').css('min-height', '100%');
    }, 100);
    
    $('#bgg').attr('class', bgs[0]).fadeTo('fast', 0);
    $('#bgg2').attr('class', bgs[1]).fadeTo('fast', 1);
    */

    //alert(document.body.scrollHeight + " " + document.body.clientHeight);

    $('.portfolioimage').mouseover(function() {
        $(this).hover({ color: '#0E93CD', color2: '#0E93CD' });
    });

    //    $('a').mouseover(function() {
    //        $(this).hover({ color: '#0E93CD', color2: '#0E93CD' ,bg:true});
    //    });

    $('.portfolioimage').mouseout(function() {
        $(this).hover({ color: 'white', color2: '' });
    });

    $('#footer_block_images_container.top .block').mouseover(function() {
        $(this).hover({ color: '#1595CC', color2: 'red' });
    });

    $('#footer_block_images_container.top .block').mouseout(function() {
        $(this).hover({ color: '#DBDBDB', color2: '#DBDBDB' });
    });


    //
    $('.footer_box .title a').livequery('mouseover', function() {
        $(this).animate(
            { 'paddingLeft': '15px'
              , 'backgroundPosition': '0pt 4pt'
            }
        );
        return false;
    });

    $('.footer_box .title a').livequery('mouseout', function() {

        $(this).animate(
            {
                'paddingLeft': '0',
                'backgroundPosition': '-250px 3pt'
                //'bgImage': 'url(/themes/standart/images/icons/a-white.gif)'
                //'bgImage': '/themes/standart/images/icons/a-white.gif'
            }
        );
        return false;

    });


    //$("a[rel='image]").facebox();
    $("a[rel=image]").livequery(function() { $(this).facebox(); });

    //$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#bdbdbd' });
    $.blockUI.defaults.pageMessage = blockUIPageMessage;
    $.extend($.blockUI.defaults.displayBoxCSS, { color: '#00a', backgroundColor: '#000' });

    $("a[rel='facebox']").livequery('click', function() {
        __url = $(this).attr("href");
        $.blockUI({ message: blockUIPageMessage });

        $.ajax({
            url: __url
            , cache: true
            , error: function() { alert('3rr0r 4ccur3d.'); }
            , success: function(html) {
                var __html = $('#login', html).html();
                $.blockUI({ message: __html, backgroundColor: "#f00", paddingLeft: "20px;"
                });
                //alert(__html.html());
            }
        });
        return false;
    });


    // footer admin login click handler
    $("a[rel='block']").click(function(e) {
        $.blockUI({ css: {
                        width: '540px', padding: '10px', border: 'solid 5px #bdbdbd'
                        //, top: ($(window).height() - 560) / 2 + 'px',
                        ,left: ($(window).width() - 540) / 2 + 'px'
        }
            , message: '<iframe src=\"/ajax/login.aspx\" frameborder="0" scrolling="no" style=\"width:100%;border:none;\"></iframe>'
        });
        //$.post('/ajax/login.aspx', '', ss);
        return false;
    });


    // all "href=#" urls' click handler
    $("a[href='#']").livequery('click', function(e) {
        $.facebox("This url hasn't been implemented yet.");
        //e.preventDefault(false);
        //$("div#home-flash .panel:first").css("position", "relative").animate({ left: d });
        //d -= 50;
        return false;
    });

});

function ss(html) { $.blockUI({ message: html }); return false; }

function __unblock() {$.unblockUI();return false; }
    