﻿var isHoverMenu = false;
$(window)._scrollable();
$(document).ready(function () {

    Cufon.replace('ul.contentTabla li .col1, .item_menu_lateral_in .link_lateral, .contentTabla2 .col1', { fontFamily: 'Swis721 Md BT' });
    Cufon.replace('.login, .rootMenuItem', { fontFamily: 'Swis721 Hv BT' });
    Cufon.replace('.user, .ContentGetStarted div a h1', { fontFamily: 'Swis721 BT' });

    //Internal Menu
    var alwaysVisibleTop = ($(window).height() / 2) - ($('.alwaysVisible').height() / 2);

    $(window).scroll(function () {
        alwaysVisibleTop = ($(window).height() / 2) - ($('.alwaysVisible').height() / 2);
        var top = ($(window).scrollTop() + alwaysVisibleTop) + "px"
        $('.alwaysVisible').animate({ top: top }, { queue: false, duration: 150 });
        if ($(".alwaysVisible span").html() == "x") openCloseMenu(false);
    });

    $('.alwaysVisible').css("top", alwaysVisibleTop + "px");

    //hover    
    $(".alwaysVisible").mouseenter(function () {        
        isHoverMenu = true;
        setTimeout("testOpenMenu(true);", 400);
    }).mouseleave(function () {
        isHoverMenu = false;
        setTimeout("testOpenMenu(false);", 200);
    });


    //lightbox
    $('a[class^="imgLightBox"]').lightBox();
    $('a[class^="imgLightBox"]').append("<img class='imglup' src='/portals/0/skins/corensic2011/img/SliceLupa.png' />")
    $('a[class^="imgLightBox"] .imglup').css({ opacity: 0.5 });
	
	
	/*$('.alwaysVisible a').each(function(){
			ref = $(this).attr('href');
			$(this).attr('href','?');
			$(this).click(function() {
				$.scrollTo( ref, 1000);
				return false;
			});
	}) //onclick="$.scrollTo( '#item', 1000 );" */
	
});

function testOpenMenu(open) {
    if (isHoverMenu && open) openCloseMenu(true);
    else if (!isHoverMenu && !open) openCloseMenu(false);
}

function openCloseMenu(open) {
    $('.alwaysVisible').animate({ width: open ? "240px" : "20px" }, { queue: false, duration: 500 });
    $(".alwaysVisible span").html(open ? "x" : "+");
}

function validate(summary_header, summary_list, validations) {
    var failures = [];
    $.each(validations, function(i, v) {
        try {
            $("#" + v.id).parent().next().css("background-image", "url(/Portals/0/Images/ValidEntry.png)");
            var value = v.value == null ? "" : v.value;
            var script_result = true;
            if (v.script != null) {
                script_result = eval(v.script);
            }
            var regex_result = true;
            if (v.regex != null) {
                regex_result = value.match(v.regex) != null;
            }
            if (!(script_result && regex_result)) failures.push(v);
        } catch (e) {
            if ((window['console'] !== undefined)) {
                console.log(e);
            }
        }
    });

    if (failures.length > 0) {
        summary_header.show();
        summary_header.scrollTop();
        summary_list.show();
    }

    var summary_element = summary_list;
    summary_element.html("");
    $.each(failures, function(i, v) {
        try {
            $("#" + v.id).parent().next().css("background-image", "url(/Portals/0/Images/InvalidEntry.png)");
            summary_element.append("<li>" + v.message + "</li>");
        } catch (e) {
            if ((window['console'] !== undefined)) {
                console.log(e);
            }
        }
    });

    return failures;
}












