﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

//Setup the Drop down
$.elementReady('brand-searchbox', function () {
	$("#brand-searchbox").find("select").uniform();
});

//Fix Borders on Tables with empty cells
$.elementReady('brand-footer', function () {
	$(".ms-listviewtable td").each(function(){
		$(this).html($(this).html() + "&nbsp;");
	})
});




//Setup list RSS link if enabled

// List types to enable (Template ID #)
var ListTypes = new Array();

//Calendar List
ListTypes.push(106);

//Alert List
ListTypes.push(104);

//Contact List
ListTypes.push(105);

//Document Lib
ListTypes.push(101);

//Photo Lib
ListTypes.push(109);

//Generic List (Like Jobs)
ListTypes.push(100);

$.elementReady('brand-content-wrap-3', function () {

    //List Flag
    isRSSType = false;

    //Loop through and test types
    $(ListTypes).each(function (index) {

        if (g_wsaListTemplateId == ListTypes[index])
            isRSSType = true;
    });

    //If the list has Jobs in the title
    if ($("#brand-title").size() > 0) {
        try {
            if ($("#brand-title").text().match("Job").length > 0)
                isRSSType = true
        }
        catch (err) { }
        
    }

    //If the page is an Admin page
    if (window.location.pathname.indexOf("_layouts") > 0)
        isRSSType = false;

    //If the page is display one item page
    if (window.location.pathname.indexOf("DispForm.aspx") > 0)
        isRSSType = false;

    //Is it the proper list type?
    if (isRSSType) {

        //If there isn't an RRS link already
        if ($("#brand-list-rss").size() < 1) {

            //If RSS is enabled for this page
            if ($("link[type='application/rss+xml']").size() > 0) {

                $("#brand-page").prepend(
                $("<div>").attr("id", "brand-list-rss").addClass("s4-notdlg").append(
                $("<a>").attr("href", $("link[type='application/rss+xml']").attr("href")).text("Subscribe to be notified of new items")
                ));

            }
        }
    }
});


//Alert Closing
$.elementReady('brand-box-alert', function () {

	//Check for cookies
	$(this).find(".box-alert").each(function () {

		if ($.cookie($(this).attr("id")) != null) {
			$(this).remove();
		}


	})

	//If there are no longer any alerts. Turn it off!
	if ($("#brand-box-alert .box-alert").size() < 1) {
		$("#brand-box-alert").remove();
	} 
	else // Show the alerts (They are turned off by default to avoid flickering
	{
		$("#brand-box-alert").show();
	}



	//Setup the clicking of the alert
	$(this).find(".close").click(function () {

		//Set cookie to longer display this alert
		$.cookie($(this).parent().parent().attr("id"), "turnoff", { path: '/' });

		//Remove this element
		$(this).parent().parent().remove();

		//And if it's the only one. Remove the whole alerts console area
		if ($("#brand-box-alert .box-alert").size() < 1) {
			$("#brand-box-alert").remove();
		}

		return false;
	});


});

