// Start my jQuery:
$(document).ready(function() {

    // Search box:
    var searchString = 'חיפוש חופשי...';
    $("#header input").attr('value', searchString)
					  .focus(function() { if (this.value === searchString) { this.value = ''; $(this).addClass('active'); } })
					  .blur(function() { if (this.value === '') { this.value = searchString; $(this).removeClass('active'); } });
    // Question Box
    $('#sideColumn div.questionBox input, #sideColumn div.questionBox textarea')
					  .focus(function() { if (this.value === this.title) { this.value = ''; $(this).addClass('active'); } })
					  .blur(function() { if (this.value === '') { this.value = this.title; $(this).removeClass('active'); } });
					  
    // Submenu:
    var menuDelayTime;
    $('#menu div a').hover(function() {
        var thisMenu = $('#menu ul');
        if (thisMenu.children("li").length > 0) {
            if (thisMenu.is(":hidden") && thisMenu.not(':animated')) {
                clearTimeout(menuDelayTime);
                thisMenu.css({ opacity: 0, height: 0, display: 'block' }).animate({ opacity: 1, height: 83 }, 700, function() {
                    $('#menu ul').removeAttr("style").css({ display: 'block' }); // IE fix
                });
            }
        }
    }
	, function() {
	    clearTimeout(menuDelayTime);
	    menuDelayTime = setTimeout(function() { menuDelayMouseout() }, 1000);
	});

    $("#menu ul").hover(function() {
        clearTimeout(menuDelayTime);
    }).mouseleave(function() {
        clearTimeout(menuDelayTime);
        menuDelayTime = setTimeout(function() { menuDelayMouseout() }, 1000);
    });



    function menuDelayMouseout() {
        $('#menu ul').stop().animate({ opacity: 0, height: 0 }, 400, function() {
            $('#menu ul').css({ display: 'none' });
        });
    }

    // Home Page center-scrolling Menu:
    $('#homeMenu div.block').jScrollPane({ dragMinHeight: 14, dragMaxHeight: 14, showArrows: true, scrollbarWidth: 14, arrowSize: 14, scrollbarOnLeft: true });
    $('#homeMenu .scrollWrap').css({ display: 'none' });

    var homeMenuDelayTime;
    $('#homeMenu ul li').hover(
		function() {
		    clearTimeout(homeMenuDelayTime);
		    delayMouseout();
		    $(this).addClass('active');
		},
		function() {
		    clearTimeout(homeMenuDelayTime);
		    homeMenuDelayTime = setTimeout(function() { delayMouseout() }, 1000);
		});

    function delayMouseout() {
        $('#homeMenu ul li').removeClass('active');
    }

    // Checks browser type and adds classes to the body to reflect it
    var userAgent = navigator.userAgent.toLowerCase();
    if ($.browser.msie) {  // Is this a version of IE?
        var browserVersion = $.browser.version.substring(0, 1);
        $('body').addClass('browserIE' + browserVersion); // Add the version number
        if (browserVersion == 7) { var thisIsIE7 = true }
    }
    // Is this a version of Opera?
    if ($.browser.opera) { $('body').addClass('browserOpera'); }

    if (thisIsIE7) {
        $('.search button, .search input').hover(function() {
            $(this).addClass('hover');
        }, function() {
            $(this).removeClass('hover');
        });
    }

    // End my jQuery Script
    var params = { wmode: 'transparent' };
    var flashvars = {};
    var attributes = {};
    //embed the logo swf
    swfobject.embedSWF("/resources/flash/logo.swf", "inner_logo_image", "123", "140", "9.0.0", "/resources/flash/expressInstall.swf", flashvars, params, attributes);
    //embed the clients swf
    swfobject.embedSWF("/resources/flash/Clients.swf", "clients_flash_content", "180", "155", "9.0.0", "/resources/flash/expressInstall.swf", flashvars, params, attributes);

    $("a.show_demo_movie").fancybox({
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        width: 791,
        height: 450
    });

    $("#upperMenu").children("a").mouseover(function() {
        $(this).addClass("active");
    }).mouseout(function() {
        $(this).removeClass("active");
    });

    $("#homeMenu ul li").removeClass("active");
});

function generateBanner(width, height, container, id, path, attr) {
    swfobject.embedSWF(path, container, width, height, "9.0.0", "/resources/flash/expressInstall.swf");
}
