$(document).ready(function()
{
	$('#logo').css('cursor', 'pointer');
    $('#logo').click(function()
	{
        window.location = '/';
	});


	$("#resources-button").click(function()
    {
        window.location = window.location + 'resources';
	});

    $("#resources-button").hover(function()
	{
		$("#resources-button-tooltip").show();
	}, function()
	{
		$("#resources-button-tooltip").hide();
    });

    $('#resources-container .pi-resources .title').css('cursor', 'default');

	$('#toolbar').css('cursor', 'pointer');
    $("#toolbar").click(function(e)
    {
        var mouseX = e.pageX - this.offsetLeft;
	    var mouseY = e.pageY - this.offsetTop;

        if (mouseX < 173)
        {
			window.location = '/need-more-information/';
        }
        else
		{
			window.location = '/visitors-poll/';
		}
    });

    $("#toolbar").hover(function(e)
    {
    }, function()
	{
        $(this).css('background', 'transparent url(/images/toolbar.jpg) top left no-repeat');
	});

	$("#toolbar").mousemove(function(e)
	{
        var mouseX = e.pageX - this.offsetLeft;
	    var mouseY = e.pageY - this.offsetTop;

        if (mouseX < 173)
        {
            $(this).css('background', 'transparent url(/images/slantBtns_h1.jpg) top left no-repeat');
        }
        else
		{
            $(this).css('background', 'transparent url(/images/slantBtns_h2.jpg) top left no-repeat');
		}

	});

    $("#resources-container .resource-box .expand").click(function(e)
    {
		$(e.target).parents().map(function () { return $(this).attr('class'); }).each(function(idx, classes)
	    {
			if (classes.indexOf('resource-box') >= 0)
			{
				jQuery.each(classes.split(' '), function()
				{
					if (this != 'resource-box')
					{
                        //console.log('Clicked on section: ' + this);
						//console.log('rel is: ' + $('.' + this).attr('rel'));
						//console.log('location is: ' + "/lightbox/" + $('.' + this).attr('rel') + "/resources/" + this + "/?width=640&height=100");
                        tb_show("lightbox-" + this + ".jpg", "/lightbox/resources/" + $('.' + this).attr('rel') + "/" + this + "/?width=300&height=50", "", "true");
					}
				});
			}
		});
    });

    $("#resources-container .resource-box").not('.pi-resources').hover(function()
    {
		$(this).css("text-decoration", "underline");
	}, function()
	{
		$(this).css("text-decoration", "none");
	});


    $(".recent-item").click(function()
    {
		// get the second class which is the parameter for which notice to display
		var arrayOfClasses = $(this).attr('class').split(' ');
		loadPresentation($(this).attr('rel'),arrayOfClasses[1]);
    });

    $(".recent-item").hover(function()
    {
		$(this).css("text-decoration", "underline");
	}, function()
	{
		$(this).css("text-decoration", "none");
	});

    if ($.cookie('isHCP') != 'true')
    {
        if (document.location.pathname != '/notice/')
        {
            tb_show("pixel_white.jpg", "/lightbox/are-you-a-hcp/?height=180&width=350&modal=true", "");
        }
    }
});

function isHCP()
{
    $.cookie('isHCP', 'true', { path: '/', expires: 120 });
    tb_remove();
}

function loadPresentation(url,notice)
{
	if (notice == null)
	{
		notice = 'standard';
	}

	if ($.cookie('postProgram') != 'true')
	{
        tb_show("lightbox-post-program-survey.jpg", "/lightbox/post_program_survey/?url=" + url + "&height=500&width=830", "");
        $.cookie('postProgram', 'true', { path: '/', expires: 120 });
    }
    window.open("/notice/?notice="+notice+"&url="+url);
}

function gotoMerck()
{
    window.location = 'http://www.merck.com/';
}
