$j(document).ready(function() {
    $j('input[title!=]').hint();

    $j('.loginBoxTooltip').cluetip({
        sticky: true,
        activation: 'click',
        positionBy: 'bottomTop',
        topOffset: 20,
        leftOffset: 20,
        cluetipClass: 'rounded',
        width: '200px',
        //height: 'auto',
        showTitle: true,
        arrows: false,
        dropShadow: false,
        closeText: '<img src="/img/tooltip/close.png" alt="Zamknij" title="Zamknij" />',
        local: true,
        cursor: 'pointer',
        fx: {
            open: 'show'
        }
    });
      
/*
	$j('.introMore').cluetip({
		sticky: true,
		activation: 'click',
		cluetipClass: 'rounded',
		width: '220px',
		//height: 'auto',
		showTitle: true,
		arrows: true,
		dropShadow: false,
		ocal: true,
		cursor: 'pointer',
		fx: {
		open: 'show'
		//openSpeed: 'fast'
		}
	});    
*/
    $j('.loginBoxTooltip, #cluetip-outer, #cluetip-arrows, .katalogzobaczcaly a, #href205 a').mouseout(onmouseout_cluetip);
    $j('.loginBoxTooltip, #cluetip-outer, #cluetip-arrows, .katalogzobaczcaly a, #href205 a').mouseover(onmouseover_cluetip);

  preloadImgList[preloadImgList.length] = '/img/tooltip/rarrowleft.gif';
  preloadImgList[preloadImgList.length] = '/img/tooltip/rarrowright.gif';
  preloadImgList[preloadImgList.length] = '/img/tooltip/rarrowdown.gif';
  preloadImgList[preloadImgList.length] = '/img/tooltip/rarrowup.gif';
  preloadImgList[preloadImgList.length] = '/img/tooltip/bl.gif';
  preloadImgList[preloadImgList.length] = '/img/tooltip/tl.gif';
  preloadImgList[preloadImgList.length] = '/img/tooltip/tr.gif';
  preloadImgList[preloadImgList.length] = '/img/tooltip/br.gif';
  preloadImgList[preloadImgList.length] = '/img/tooltip/close.gif';
  preloadImgList[preloadImgList.length] = '/img/play_hover.png';
  preloadImgList[preloadImgList.length] = '/img/layout/default/li4.gif';
  preloadImgList[preloadImgList.length] = '/img/layout/default/li_bg80.png';

    var menuTimeout = null;
    
    $j("#menu li div.l_bg").hover(
      function () {
        clearTimeout(menuTimeout);
        menuTimeout = null;
        $j(this).addClass("_hover");
        $j('#menu li div.l_bg.hover:not(._hover)').removeClass("hover");
        $j(this).addClass("hover");
        $j('.selectedsubmenu').addClass("selectedsubmenu_hover");
      }, 
      function () {
        $j(this).removeClass("_hover");
        if(menuTimeout == null){
            menuTimeout = setTimeout(function() {
                $j('#menu li div.l_bg.hover').removeClass("hover");
                $j('.selectedsubmenu').removeClass("selectedsubmenu_hover");
            }, 2000);
        }
      }
    );

    $j("#menubox li div, form input[type=text], form input[type=password], form textarea").hover(
      function () {
        $j(this).addClass("hover");
        if($j(this).hasClass("Ico")){
            $j(this).addClass("hoverIco");
        }
      }, 
      function () {
        $j(this).removeClass("hover");
        if($j(this).hasClass("Ico")){
            $j(this).removeClass("hoverIco");
        }
      }
    );


    $j("form input[type=text], form input[type=password], form textarea").focus(
      function () {
        $j(this).addClass("focus");
        if($j(this).hasClass("Ico")){
            $j(this).addClass("focusIco");
        }
      }
    );

    $j("form input[type=text], form input[type=password], form textarea").blur(
      function () {
        $j(this).removeClass("focus");
        if($j(this).hasClass("Ico")){
            $j(this).removeClass("focusIco");
        }
      }
    );
    
});

var recalculateMainHeightCounter = 0;

$j(window).load(function(){
    recalculateMainHeight();
    if(recalculateMainHeightCounter<3){
        recalculateMainHeightCounter++;
        setTimeout("recalculateMainHeight()", 1000);
    }
});

function recalculateMainHeight () {
    if($$('div.leftbar')[0].getHeight() > $('viewbox').getHeight()){
        var hght = $$('div.leftbar')[0].getHeight();
//        $('viewbox').style.height = hght + 'px';
        if($j.browser.msie && parseInt($j.browser.version) < 7){
            $$('#viewbox .view')[0].style.height = (hght) + 'px';
        } else {
            $$('#viewbox .view')[0].style.minHeight = (hght) + 'px';
        }
    }
}

function insertLoadingIndicator(destination, insertMethod, message){
    if(typeof(message) == "undefined"){
        message = null;
    }
    if(insertMethod == 'replace') {
        $j(destination).empty();
    }

    if(message != null){
        $j(destination).append($j('#indicator_bar div').clone());
        $j(destination + " .indicator_bar .message").append(message);
    } else {
        $j(destination).append($j('#indicator div').clone());
    }
}


function updateAccount(){
    if($j("#account_state_box").length>0){
         new Ajax.Updater('account_state_box','/user/accounts/viewbox/', {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'account_value']});
    } else if($j("#account_value").length>0) {
         new Ajax.Updater('account_value','/user/accounts/view/', {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'account_value']});
    }
}


universalBlock = function (elem){
    elem.block({
        message: '<img src="/img/loading.gif" />',
        css: {border: '0px',backgroundColor: 'transparent'},
        overlayCss: {opacity: '0.7'}
    });
}
