//comment before upload to production
//var dev = true;
SS = {
    common: {
        init: function () {
            //UI display
            uiDisplay();
            //UI accessibility 
            uiAttr();
            // UI css appends
            uiCssAppends();
            // UI sidebar
            uiAside()
            //UI advanced css selectors
            uiCssSelect();
            //UI universal non-sorting tables
            uniTbl();
            // Search 
            defSearch()
            advSearch()
            advlistSplit();
            //search results
            seResult();

            //editing tools
            //editList();
            //editContent();
            //emailContent();
            //addList();
            //itemFav();
            printPage();
            //toolbar
            modTool();

            //bio text
            defaultBio();
            bioInner();



            //structrual modules
            siteHeader();
            siteMainav();
            sizeMenuitem();
            sFoot();
            siteNavigate();
            //end
        }
    },
    //login
    login: {
        init: function () {
            //default
            function defaultLogin() {
                $("#u-pwrecover").hide();
                $("#u-reconfirm").hide();
                $("#u-error").hide();
            }
            defaultLogin();

            //validation
            function defaultForm() {
                $(".ui-state-error").css("display", "none");
                $("span.error").css("display", "none");
            }
            defaultForm();

            //password
            function forgotPass() {
                $("#pw-forgot").live("click", function () {
                    $(this).parents(".content").find("#u-pwrecover").show().css("display", "block");
                    $(this).parents("#u-login").hide();
                    $(this).parents(".content").find("#misc").hide();
                });
            }
            forgotPass();

            function recoverPass() {
                $("#s-recover").live("click", function () {
                    $(this).parents(".content").find("#u-reconfirm").show().css("display", "block");
                    $(this).parents("#u-pwrecover").hide();
                    $(this).parents(".content").find("#misc").hide();
                });
            }
            recoverPass();

            function errPass() {
                $("#oops").live("click", function () {
                    $(this).parents(".content").find("#u-error").show().css("display", "block");
                    $(this).parents("#u-login").hide();
                    $(this).parents(".content").find("#misc").hide();
                });
            }
            errPass();

            //placeholder text
            //using jquery.placeholder.min.js
            // To test the @id toggling on password inputs in browsers that don’t support changing an input’s @type dynamically (e.g. Firefox 3.6 or IE), uncomment this:
            // jQuery.fn.hide = function() { return this; }
            // Then uncomment the last rule in the <style> element (in the <head>).
            $(function () {
                // Invoke the plugin
                l$('input, textarea').placeholder();
            });

            //end
        }
    },
    //home
    index: {
        init: function () {
            nowReg();

            // Feature Tabs
            //$(function(){
            //$('#feature .tabs').tabs();
            //$('#feature .tabs').tabs( "rotate", 5000, [ 0 ] ).tabs({fx: { opacity: 'toggle'}});
            //$("#feature .ui-tabs").addClass("tabs-bottom");
            //$("#feature .ui-tabs-nav").addClass("ui-corner-bottom");
            //$("#feature .ui-tabs-nav li").removeClass("ui-corner-top");
            //runeffect
            //$("#feature li .tabs-bottom .ui-tabs-nav, #feature li .tabs-bottom .ui-tabs-nav > *")
            //.removeClass("ui-corner-all ui-corner-top")
            //.addClass("ui-corner-bottom");
            //}); 

            // Feature Lists
            function feSplit() {
                $('#feature .splist-2').easyListSplitter({
                    colNumber: 2
                });
            }
            feSplit();

            // Hot Search Tabs
            function hsTab() {
                $("#h-s .tabs").removeClass("ui-corner-all");
                $("#h-s .tabs .ui-tabs-nav").removeClass("ui-corner-all");
            }
            hsTab();

            // Feature Tool Rotation Random
            function showTool() {
                var theTool = (".content #tool-feature .atool");
                var toolRandom = Math.floor(Math.random() * $(".content #tool-feature .atool").length);
                $(".content #tool-feature .atool:eq(" + toolRandom + ")").show();
            }
            showTool();

        }
    },
    //projects
    proj: {
        init: function () {
            // tertiary navigation
            function gammaTabs() {
                $('.gamma .tabs').tabs();
                $(".gamma .ui-tabs-nav li").removeClass("ui-corner-top");
            }
            gammaTabs();

            // boxoffice sortable table
            // dependant jquery.dataTables.js
            $('#proj-bo').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "bInfo": false,
                "bPaginate": false,
                //"sPaginationType": "full_numbers",
                "aaSorting": [[1, "asc"]],

                "aoColumns": [
						{ "sTitle": "Weekend Prior To", "sWidth": "240px", "bSortable": true },
						{ "sTitle": "Weekend Gross", "sWidth": "190px", "bSortable": true },
						{ "sTitle": "Screens", "sWidth": "90px", "bSortable": true },
						{ "sTitle": "Average", "sWidth": "100px", "bSortable": true },
						{ "sTitle": "Cume", "sWidth": "150px", "bSortable": true }
				]
            });

            // project credits sortable table
            // dependant jquery.dataTables.js
            $('.proj-credit').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "bInfo": false,
                "bPaginate": false,
                //"sPaginationType": "full_numbers",
                "aaSorting": [[0, "asc"]],

                "aoColumns": [
						{ "sTitle": "Name", "sWidth": "30%", "bSortable": true, "bVisible": true },
						{ "sTitle": "Credit", "sWidth": "150px", "bSortable": true, "bVisible": true },
						{ "sTitle": "Credited As", "sWidth": "20%", "bSortable": true, "bVisible": true },
						{ "sTitle": "Attachment Date**", "sWidth": "110px", "bSortable": false, "bVisible": false }
				]
            });

            // http://datatables.net/release-datatables/examples/api/show_hide.html
            function attachShow() {
                $("#creditFilter").change(function () {

                    var oTable = $('.proj-credit').dataTable();
                    var sel = $("#creditFilter option:selected").val();

                    //redirect to the value from the option box
                    window.location = sel;
                });

            } attachShow();

            // project credits TV sortable table
            // dependant jquery.dataTables.js
            $('.proj-creditv').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "bInfo": false,
                "bPaginate": false,
                //"sPaginationType": "full_numbers",
                "aaSorting": [[0, "asc"]],

                "aoColumns": [
						{ "sTitle": "Name", "sWidth": "200px", "bSortable": true, "bVisible": true },
						{ "sTitle": "Credit", "sWidth": "200px", "bSortable": true, "bVisible": true },
						{ "sTitle": "Credited As", "sWidth": "200px", "bSortable": true, "bVisible": true },
						{ "sTitle": "Season Span", "sWidth": "140px", "bSortable": true, "bVisible": true },
						{ "sTitle": "Attachment Date**", "sWidth": "120px", "bSortable": false, "bVisible": false }
				]
            });

            // http://datatables.net/release-datatables/examples/api/show_hide.html
            function attachTVshow() {

                $("#creditFilterTV").change(function () {
                    var oTable = $('.proj-creditv').dataTable();
                    var sel = $("#creditFilterTV option:selected").val();
                    //alert('hi');
                    if (sel == "5") {
                        $(oTable).each(function () {
                            oTable.fnSetColumnVis(4, true);
                        });
                        //oTable.fnSetColumnVis( 4, true );
                    } else {
                        $(oTable).each(function () {
                            oTable.fnSetColumnVis(4, false);
                        });
                        //oTable.fnSetColumnVis( 4, false );
                    }
                });

            } attachTVshow();

            $(".proj-credit thead th:nth-child(4) div.DataTables_sort_wrapper").css({ "min-width": "120px", "padding-right": "0" });
            $(".proj-creditv thead th:nth-child(5) div.DataTables_sort_wrapper").css({ "min-width": "120px", "padding-right": "0" });

            // indented content
            var cellIndent = [
					"all-notes",
					"bio-text"
				];

            $.each(cellIndent, function () {
                $('.' + this + ' p').addClass("ind");
            });

            //toolbar

            //tables proj
            applyCellWidths("proj-credit-all-cat");
            applyCellWidths("proj-fin-bo-weekly");
            applyCellWidths("proj-fin-bo-summary");
            applyCellWidths("proj-tv-credit-all-cat");
            applyCellWidths("proj-t-proj");
            applyCellWidths("proj-t-leads");
            applyCellWidths("all-notes");
            //
        },
        gallery: function () {
            //gallery listing
            tnGallery();
            //img listing
            tnImg();
            //
        },
        tv: function () {
            //slider tv year series

            //
        }
    },
    //people
    peeps: {
        init: function () {
            // tertiary navigation
            function gammaTabs() {
                $('.gamma .tabs').tabs();
                $(".gamma .ui-tabs-nav li").removeClass("ui-corner-top");
            }
            gammaTabs();

            //tables part
            applyCellWidths("p-awardslist");
            applyCellWidths("p-bio-mile");
            applyCellWidths("p-bio-family");
            applyCellWidths("p-creditlist");
            applyCellWidths("unavailable");
            applyCellWidths("p-fin-bolist");
            applyCellWidths("p-fin-salary");
            applyCellWidths("p-t-cast");
            applyCellWidths("p-t-contact");
            applyCellWidths("p-t-indev");
            applyCellWidths("p-t-proj");
            applyCellWidths("all-notes");
            //
        },
        gallery: function () {
            //gallery listing
            tnGallery();
            //img listing
            tnImg();
            //
        }
    },
    //organizations
    org: {
        init: function () {
            // tertiary navigation
            function gammaTabs() {
                $('.gamma .tabs').tabs();
                $(".gamma .ui-tabs-nav li").removeClass("ui-corner-top");
            }
            gammaTabs();

            //tables org
            applyCellWidths("org-creditlist");
            applyCellWidths("org-fin-bolist");
            applyCellWidths("org-emp");
            applyCellWidths("org-t-contact");
            applyCellWidths("org-t-proj");
            applyCellWidths("org-t-proj-tv");
            applyCellWidths("all-notes");
            //  
        },
        gallery: function () {
            //gallery listing
            tnGallery();
            //img listing
            tnImg();
            //
        }
    },
    //mylists
    mlist: {
        init: function () {
            // Mylist Tabs initialize selected tab
            $("#mlist-proj").click(function () {
                $('#mylists').tabs({
                    selected: '.ui-tabs-nav #ml-proj'
                });
            });
            $("#mlist-per").click(function () {
                $('#mylists').tabs({
                    selected: '.ui-tabs-nav #ml-peo'
                });
            });
            $("#mlist-com").click(function () {
                $('#mylists').tabs({
                    selected: '.ui-tabs-nav #ml-org'
                });
            });
            $("#mlist-ctm").click(function () {
                $('#mylists').tabs({
                    selected: '.ui-tabs-nav #ml-ctm'
                });
            });


            //tables org
            applyCellWidths("proj-t-leads");
            applyCellWidths("proj-t-proj");
            applyCellWidths("p-t-cast");
            applyCellWidths("p-t-contact");
            applyCellWidths("p-t-indev");
            applyCellWidths("p-t-proj");
            applyCellWidths("org-t-contact");
            applyCellWidths("org-t-proj");
            applyCellWidths("org-t-proj-tv");
            applyCellWidths("list-crew-producer");
            applyCellWidths("list-crew-cast");
            applyCellWidths("list-crew-rep");
            //
        }
    },
    //myTools
    tools: {
        init: function () {

            // tool assistant crew default
            function defaultCrewRole() {
                $('#crew-frm').show();
                $('#crew-filter').hide();
                $('#crew-all').hide();
                $('#tool-list').hide();
            }
            defaultCrewRole();

            // tool assistant crew filter
            $('.content #crew li').live("click", function () {
                findCrew(this);
                oneCrew();
                $('#crew-ins').hide();
                selCrew();
                appendCrew();
                hideQuote();
                animQuote();
            });
            function findCrew(theone) {
                defaultCrew();
                $(theone).addClass("selected");
                $('#crew-filter').show();
                return false;
            }
            $('#crew-filter .toolResults').live("click", function () {
                resultsCrew();
                // oneCrew();
            });
            function selCrew() {
                $('#crew').addClass("selected");
            }
            // tool assistant crew filter default
            function defaultCrewFilter() {
                $('#crew-filter fieldset').not('.step-1').hide();
            }
            defaultCrewFilter();

            // tool assistant crew filter add icon to step-1			
            function appendCrew() {
                $("#crew-filter .step-1 .step-form h2").after($("#crew.selected"));
            }

            // steps in search filter
            $('#crew-filter .nextstep').live("click", function () {
                $(this).parents('.tool-assist').next().show();
                $(this).parents('.tool-assist').hide();
                hideQuote();
                animQuote();
                return false;
            });
            $('#crew-filter .prevstep').live("click", function () {
                $(this).parents('.tool-assist').prev().show();
                $(this).parents('.tool-assist').hide();
                hideQuote();
                animQuote();
                return false;
            });

            function hideQuote() {
                $('.tool-assist .h1 li span.active').hide();
            }
            function animQuote() {
                $('.tool-assist .h1 li span.active').fadeIn('2000');
            };

            // tool assistant crew results
            function resultsCrew() {
                var liCrew = $("#crew li");
                $('#crew-all').show();
                $('#crew-filter').hide();
            }
            function oneCrew() {
                $(".content #crew li").not('.selected').fadeOut('500');
            };
            function defaultCrew() {
                $('.content #crew li').removeClass("selected");
                $('#crew-filter').hide();
            };
            $('#t-crew .goto').live("click", function () {
                $('#tool-list').show();
                $('.content').hide();
                $('#crew-filter').hide();
                $('#crew-all').hide();
                return false;
            });

            // tool assistant casting, production, writer
            $('#crew-frm .toolResults').live("click", function () {
                $(this).parents('.content').find('#crew-frm').hide();
                $('#crew-all').show();
            });

            // tool assistant crew filter default
            function defaultCrewFrm() {
                $('#crew-frm fieldset').not('.step-1').hide();
            }
            defaultCrewFrm();

            // steps in search filter
            $('#crew-frm .nextstep').live("click", function () {
                $(this).parents('.tool-assist').next().show();
                $(this).parents('.tool-assist').hide();
                hideQuote();
                animQuote();
                return false;
            });
            $('#crew-frm .prevstep').live("click", function () {
                $(this).parents('.tool-assist').prev().show();
                $(this).parents('.tool-assist').hide();
                hideQuote();
                animQuote();
                return false;
            });
            // tool assistant results data tables
            $('#crew-all .display thead th:first-child').html('<input type="checkbox" name="all" value="0"><span>All</span>');
            $('#tool-crew-cat').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "sPaginationType": "full_numbers",
                "aaSorting": [[1, "asc"]],

                "aoColumns": [
                /*checkbox*/{"sWidth": "30", "bSortable": false },
						{ "sTitle": "Name", "sWidth": "190px", "bSortable": true },
						{ "sTitle": "Project", "sWidth": "330px", "bSortable": false },
						{ "sTitle": "Contact", "sWidth": "165px", "bSortable": false },
						{ "sTitle": "Agent/Mngr.", "sWidth": "150px", "bSortable": false }
				]
            });
            $('#tool-actor-cast').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "sPaginationType": "full_numbers",
                "aaSorting": [[1, "asc"]],

                "aoColumns": [
                /*checkbox*/{"sWidth": "30", "bSortable": false },
						{ "sTitle": "Start Date", "sWidth": "90px", "bSortable": true },
						{ "sTitle": "Name", "sWidth": "280px", "bSortable": true },
						{ "sTitle": "Status", "sWidth": "105px", "bSortable": true },
						{ "sTitle": "Director", "sWidth": "270px", "bSortable": true },
						{ "sTitle": "Genre", "sWidth": "90px", "bSortable": true }
				]
            });
            $('#tool-crew-prod').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "sPaginationType": "full_numbers",
                "aaSorting": [[1, "asc"]],

                "aoColumns": [
                /*checkbox*/{"sWidth": "30", "bSortable": false },
						{ "sTitle": "Start Date", "sWidth": "90px", "bSortable": true },
						{ "sTitle": "Project", "sWidth": "200px", "bSortable": true },
						{ "sTitle": "Status", "sWidth": "105px", "bSortable": true },
						{ "sTitle": "Company", "sWidth": "180px", "bSortable": true },
						{ "sTitle": "Contact", "sWidth": "170px", "bSortable": false },
						{ "sTitle": "Genre", "sWidth": "85px", "bSortable": false }
				]
            });
            $("#tool-crew-prod td:nth-child(6) p:first-child").addClass("strong");

            $('#tool-rep-rolo').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "sPaginationType": "full_numbers",
                "aaSorting": [[1, "asc"]],

                "aoColumns": [
                /*checkbox*/{"sWidth": "30", "bSortable": false },
						{ "sTitle": "Rep.Name", "sWidth": "207px", "bSortable": true },
						{ "sTitle": "Company", "sWidth": "190px", "bSortable": true },
						{ "sTitle": "Rep. Type", "sWidth": "107px", "bSortable": true },
						{ "sTitle": "Clients", "sWidth": "200px", "bSortable": false },
						{ "sTitle": "Contact", "sWidth": "131px", "bSortable": false }
				]
            });

            // tool assistant genre Lists
            $('#multi-genre .splist-3').easyListSplitter({
                colNumber: 3
            });
            // tables
            applyCellWidths("tool-production");
            applyCellWidths("tool-crew-producer");
            applyCellWidths("tool-crew-actor");
            applyCellWidths("tool-crew-reps");
            //
        }

    },
    //calendar
    cal: {
        init: function () {
            if (typeof dev != 'undefined') {
                //us film release calendar
                function usFilmRel() {
                    $.ajax({
                        url: 'inc/cal-film-release.html',
                        dataType: 'html',
                        success: function (data) {
                            $('.content .box header').after(innerShiv(data));
                            applyCellWidths("cal-film-release");
                            $("table tbody tr:nth-child(even)").addClass("alt");
                            //$("td:first-child").css("font-weight","bold");
                        }
                    });
                }
                usFilmRel();
            } else {
                applyCellWidths("cal-film-release");
                $("table tbody tr:nth-child(even)").addClass("alt");
            }


            //tables

            //
        }

    },
    calsort: {
        init: function () {
            if (typeof dev != 'undefined') {
                //us film release calendar sorting paging
                //dependant jquery.dataTables.js
                function usFilmRelSort() {
                    $.ajax({
                        url: 'inc/cal-film-release-sort.html',
                        dataType: 'html',
                        success: function (data) {
                            $('.content .box header').after(innerShiv(data));
                            // sortable table
                            // dependant jquery.dataTables.js
                            $('.cal-filmrelease-sort').dataTable({
                                "bAutoWidth": false,
                                "bJQueryUI": true,
                                "bFilter": false,
                                "bLengthChange": false,
                                "bInfo": false,
                                "bPaginate": false,
                                //"sPaginationType": "full_numbers",
                                "aaSorting": [[1, "asc"]],

                                "aoColumns": [
							{ "sTitle": "Release Date", "sWidth": "110px", "bSortable": true },
							{ "sTitle": "Title", "sWidth": "250px", "bSortable": true },
							{ "sTitle": "Director", "sWidth": "140px", "bSortable": false },
							{ "sTitle": "Rating", "sWidth": "60px", "bSortable": true },
							{ "sTitle": "Distributor", "sWidth": "190px", "bSortable": false },
							{ "sTitle": "Genre", "sWidth": "195px", "bSortable": false }
							]
                            });
                        }

                    });
                }
                usFilmRelSort();
            } else {
                // sortable table
                // dependant jquery.dataTables.js
                $('.cal-filmrelease-sort').dataTable({
                    "bAutoWidth": false,
                    "bJQueryUI": true,
                    "bFilter": false,
                    "bLengthChange": false,
                    "bInfo": false,
                    "bPaginate": false,
                    //"sPaginationType": "full_numbers",
                    "aaSorting": [[1, "asc"]],

                    "aoColumns": [
					{ "sTitle": "Release Date", "sWidth": "110px", "bSortable": true },
					{ "sTitle": "Title", "sWidth": "250px", "bSortable": true },
					{ "sTitle": "Director", "sWidth": "140px", "bSortable": false },
					{ "sTitle": "Rating", "sWidth": "60px", "bSortable": true },
					{ "sTitle": "Distributor", "sWidth": "190px", "bSortable": false },
					{ "sTitle": "Genre", "sWidth": "195px", "bSortable": false }
					]
                });
            }


        }

    },
    //admin
    admin: {
        init: function () {
            // admin group listing
            $('.admin-groups-list').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "bInfo": false,
                "bPaginate": false,
                //"sPaginationType": "full_numbers",
                "aaSorting": [[5, "asc"]],

                "aoColumns": [
            		{ "sTitle": "Group Name", "sWidth": "200", "bSortable": true },
					{ "sTitle": "Active Accounts", "sWidth": "120px", "bSortable": true },
					{ "sTitle": "Max Accounts", "sWidth": "110px", "bSortable": true },
					{ "sTitle": "Group Status", "sWidth": "110px", "bSortable": true },
					{ "sTitle": "Expiration", "sWidth": "100px", "bSortable": true },
					{ "sTitle": "Created", "sWidth": "65px", "bSortable": true },
					{ "sTitle": "Modified", "sWidth": "65px", "bSortable": true }
			]
            });
            $(".admin-groups-list td:nth-child(3)").css("font-weight", "bold");
            $(".admin-groups-list td:nth-child(4)").css("font-weight", "bold");
            $(".admin-groups-list td:nth-child(5)").css("font-weight", "bold");

            // admin group userlisting
            $('.admin-group-userlist').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "bInfo": false,
                "bPaginate": false,
                //"sPaginationType": "full_numbers",
                "aaSorting": [[5, "asc"]],

                "aoColumns": [
            		{ "sTitle": "User Name", "sWidth": "160", "bSortable": true },
					{ "sTitle": "Email", "sWidth": "120px", "bSortable": true },
					{ "sTitle": "Type", "sWidth": "100px", "bSortable": true },
					{ "sTitle": "Status", "sWidth": "100px", "bSortable": true },
					{ "sTitle": "Last Login", "sWidth": "160px", "bSortable": true },
					{ "sTitle": "Created", "sWidth": "65px", "bSortable": true },
					{ "sTitle": "Modified", "sWidth": "65px", "bSortable": true }
			]
            });
            $(".admin-groups-userlist td:nth-child(3)").css("font-weight", "bold");

            // admin group userlisting
            $('.admin-userlist').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                "bInfo": false,
                "bPaginate": false,
                //"sPaginationType": "full_numbers",
                "aaSorting": [[5, "asc"]],

                "aoColumns": [
            		{ "sTitle": "Name/Title", "sWidth": "160", "bSortable": true },
					{ "sTitle": "Email", "sWidth": "180px", "bSortable": true },
					{ "sTitle": "Group", "sWidth": "100px", "bSortable": true },
					{ "sTitle": "Type", "sWidth": "80px", "bSortable": true },
					{ "sTitle": "Last Login", "sWidth": "120px", "bSortable": true },
					{ "sTitle": "Created", "sWidth": "65px", "bSortable": true },
					{ "sTitle": "Modified", "sWidth": "65px", "bSortable": true },
					{ "sTitle": "Status", "sWidth": "65px", "bSortable": true }
			]
            });
            $(".admin-userlist td:nth-child(2) a").css("word-wrap", "break-word");
            $(".admin-userlist td:nth-child(2) a").css("width", "160px");
            //
            addGroup();
            addUser();
            newPW();
            resetPW();
        }
    },
    //season tv
    season: {
        init: function () {
            //tables
            applyCellWidths("proj-s-e-air");
            //end
        }
    },
    //episode tv
    episode: {
        init: function () {
            //tables
            applyCellWidths("proj-e-air");
            //end
        }
    },
    //searchresults
    searchresults: {
        init: function () {
            //search results project sorting paging
            //dependant jquery.dataTables.js
            $('.results-project').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                //"bInfo": false,
                "bPaginate": true,
                "sPaginationType": "full_numbers",
                "aaSorting": [[0, "asc"]],

                "aoColumns": [
                /*checkbox*/{"sTitle": "#", "sWidth": "70", "bSortable": true },
						{ "sTitle": "Name", "sWidth": "300px", "bSortable": true },
						{ "sTitle": "Type", "sWidth": "140px", "bSortable": false },
						{ "sTitle": "Status", "sWidth": "80px", "bSortable": true },
						{ "sTitle": "Release", "sWidth": "190px", "bSortable": true },
						{ "sTitle": "AKA", "sWidth": "195px", "bSortable": true },
						{ "sTitle": "Last Updated", "sWidth": "125px", "bSortable": true }
						]
            });

            //search results project sorting paging
            //dependant jquery.dataTables.js
            $('.results-part').dataTable({
                "bAutoWidth": false,
                "bJQueryUI": true,
                "bFilter": false,
                "bLengthChange": false,
                //"bInfo": false,
                "bPaginate": true,
                "sPaginationType": "full_numbers",
                "aaSorting": [[0, "asc"]],

                "aoColumns": [
                /*checkbox*/{"sTitle": "#", "sWidth": "70", "bSortable": true },
						{ "sTitle": "Name", "sWidth": "180px", "bSortable": true },
						{ "sTitle": "Company", "sWidth": "260px", "bSortable": true },
						{ "sTitle": "Role", "sWidth": "180px", "bSortable": true },
						{ "sTitle": "AKA", "sWidth": "195px", "bSortable": true },
						{ "sTitle": "Credit", "sWidth": "215px", "bSortable": true }
						]
            });
            //end do stuff 
        }

    }
    //end SS
}

UTIL = {

    fire: function (func, funcname, args) {

        var namespace = SS;  // indicate your obj literal namespace here

        funcname = (funcname === undefined) ? 'init' : funcname;
        if (func !== '' && namespace[func] && typeof namespace[func][funcname] == 'function') {
            namespace[func][funcname](args);
        }

    },

    loadEvents: function () {

        var bodyId = document.body.id;

        // hit up common first.
        UTIL.fire('common');

        // do all the classes too.
        $.each(document.body.className.split(/\s+/), function (i, classnm) {
            UTIL.fire(classnm);
            UTIL.fire(classnm, bodyId);
        });

        UTIL.fire('common', 'finalize');

    }

};
// kick it all off here 
$(document).ready(UTIL.loadEvents);

//----------------------

//project tv years slider
$(function () {
    //scrollpane parts
    var scrollPane = $('.scroll-pane');
    var scrollContent = $('.scroll-content');

    //build slider
    var scrollbar = $(".scroll-bar").slider({
        slide: function (e, ui) {
            if (scrollContent.width() > scrollPane.width()) { scrollContent.css('margin-left', Math.round(ui.value / 100 * (scrollPane.width() - scrollContent.width())) + 'px'); }
            else { scrollContent.css('margin-left', 0); }
        }
    });

    //append icon to handle
    var handleHelper = scrollbar.find('.ui-slider-handle')
	.mousedown(function () {
	    scrollbar.width(handleHelper.width());
	})
	.mouseup(function () {
	    scrollbar.width('100%');
	})
	.append('<span class="ui-icon ui-icon-grip-dotted-vertical"></span>')
	.wrap('<div class="ui-handle-helper-parent"></div>').parent();

    //change overflow to hidden now that slider handles the scrolling
    scrollPane.css('overflow', 'hidden');

    //size scrollbar and handle proportionally to scroll distance
    function sizeScrollbar() {
        var remainder = scrollContent.width() - scrollPane.width();
        var proportion = remainder / scrollContent.width();
        var handleSize = scrollPane.width() - (proportion * scrollPane.width());
        scrollbar.find('.ui-slider-handle').css({
            width: handleSize,
            'margin-left': -handleSize / 2
        });
        handleHelper.width('').width(scrollbar.width() - handleSize);
    }

    //reset slider value based on scroll content position
    function resetValue() {
        var remainder = scrollPane.width() - scrollContent.width();
        var leftVal = scrollContent.css('margin-left') == 'auto' ? 0 : parseInt(scrollContent.css('margin-left'));
        var percentage = Math.round(leftVal / remainder * 100);
        scrollbar.slider("value", percentage);
    }
    //if the slider is 100% and window gets larger, reveal content
    function reflowContent() {
        var showing = scrollContent.width() + parseInt(scrollContent.css('margin-left'));
        var gap = scrollPane.width() - showing;
        if (gap > 0) {
            scrollContent.css('margin-left', parseInt(scrollContent.css('margin-left')) + gap);
        }
    }

    //change handle position on window resize
    $(window)
	.resize(function () {
	    resetValue();
	    sizeScrollbar();
	    reflowContent();
	});
    //init scrollbar size
    setTimeout(sizeScrollbar, 10); //safari wants a timeout
});

//print
$(document).ready(function () {
    $('.toolPrint').bind("click", function () {
        $(this).parents("html").addClass("fprint");
    });
});


/*
* jQuery inputfile plugin 0.1
* requires jquery
* http://wnas.nl/
* Copyright (c) 2008 Wilfred Nas
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*/

/*
to intiate the  function do
jQuery('foobar').inputfile();
	
NOTE  the input type file has to have an unique id.
	
it first add's a class to the input file (style / hide with css)
then we create a div with an input and a span (span for button)
on change we set the value of file in the text...
	
DONE
*/
$.fn.inputfile = function () {

    $(this).addClass('file');
    var fii = $(this).attr('id');
    $(this).after('<div class="fakefile"><span class="wrap"><input type="text" class="fakefile ' + fii + ' " /><button class="find-results">Browse...</button></span></div>');
    $(this).change(function () {
        var val = $(this).val();
        $('.' + fii).val(val);
    });

}

//autocomplete
$(function () {
    var keywords = [
		"1100s", "12th century", "1500s", "16th century", "1700s", "1800s", "18th century", "1900s",
		"1910s", "1920s", "1930s", "1940s", "1950s", "1960s", "1970s", "1980s", "1990s", "19th century",
		"2d", "3d", "3-D", "800s", "9/11", "9th century", "abduction", "abuse", "accident", "acting", "actor",
		"addiction", "adolescence", "adoption", "adultery", "affair", "african-american", "afterlife", "aids",
		"airplane", "alcoholism", "alien", "angel", "animal", "anime", "apocalypse", "architecture", "argentina",
		"arkansas", "armed forces", "army", "art", "article", "artisan", "assassin", "astronaut", "athlete",
		"autobiography", "automobile", "aviation", "awards", "baby", "backdoor pilot", "banking", "baseball", "basketball",
		"beatles", "beauty", "behind the scenes", "benefit", "bible", "biking", "bilingual", "bio", "biography",
		"biological", "biopic", "bird", "black", "black comedy", "boat", "bollywood", "book", "bounty hunter", "boxing",
		"british series", "british television series", "broadway", "brothers", "buddy", "buffalo", "business",
		"cancer", "caper", "cars", "cat", "celebrity", "cg animation", "cgi", "championship", "character study",
		"chase", "chefs", "child", "childhood", "children", "children's", "children's book", "chocolate", "christianity",
		"christmas", "CIA", "cinema", "civil rights", "civil war", "claymation", "clips", "college", "college basketball",
		"college football", "combat", "comedian", "comedy", "comic", "comic book", "comic strip", "comics", "coming of age",
		"coming-of-age", "competion", "competition", "competiton", "compilation", "computer", "con artist", "concert",
		"conspiracy", "contest", "cooking", "cop", "corruption", "court", "courtroom", "cowboy", "craft", "creature",
		"cricket", "crime", "cult", "culture", "curling", "curse", "cycling", "dance", "dark", "death", "decorating",
		"deformity", "demon", "depression", "design", "detective", "dinosaur", "disability", "disappearance", "disaster",
		"discussion", "disease", "divorce", "dna", "doctor", "docudrama", "documentary", "docusoap", "dog", "dog show",
		"dragon", "dragons", "dramedy", "drugs", "ecology", "economy", "education", "educational", "elderly", "election",
		"emotion", "energy", "ensemble", "entertainment", "environment", "environmental", "environmentalist", "epic", "episodic",
		"erotic", "escape", "espionage", "exercise", "exotic", "experiment", "extra-sensory perception", "fable", "fairies",
		"fairy tale", "faith", "fame", "family", "fantasy", "farce", "fashion", "father/daughter", "father/son", "fatherhood",
		"FBI", "feature", "feature film", "female", "femme fatale", "fighting", "film", "film criticism", "film noir", "filmmaking",
		"finals", "firefighter", "fish-out-of-water", "fitness", "flashback", "flying", "food", "football", "format", "franchise",
		"friendship", "fugitive", "future", "futuristic", "gambling", "game", "game show", "gang", "gangs", "gangster", "gay", "gender",
		"genealogy", "ghost", "ghosts", "global", "gnome", "golf", "gothic", "government", "graphic novel",
		"graphic novel series", "grief", "grieving", "halloween", "haunted", "health", "heist", "hero", "heroine",
		"hidden-camera", "high school", "hijacking", "himalaya", "historical", "hitman", "hockey", "hollywood",
		"Holocaust", "home", "home improvement", "home renovation", "homeless", "homosexuality", "hoover", "horse racing",
		"hostage", "human rights", "ice skating", "identity", "illness", "imaginary friend", "immigration", "immortality",
		"improv", "india", "infidelity", "informational", "inner city", "instructional", "interactive", "international", "internet",
		"invasion", "investigation", "iraq", "jail", "jesus", "journalism", "journey", "junta", "justice", "kidnap", "kung fu", "law",
		"law enforcement", "legal", "legend", "lennon", "lion", "literary", "literature", "live", "live action", "live-action", "love",
		"love triangle", "luge", "mafia", "magazine", "magic", "makeover", "marines", "marriage", "martial arts", "mccartney", "media",
		"medical", "medical condition", "medieval", "melodrama", "memoir", "mental illness", "military", "mining", "miniseries", "mob",
		"mockumentary", "mocumentary", "money", "monster", "montana", "mother", "mother/daughter", "mother/son", "motherhood",
		"motion-capture", "motorcycle", "mountain climbing", "movie", "movies", "murder", "music", "musician", "mutant", "mystery", "myth",
		"Mythology", "natural disaster", "nature", "navy", "nazi", "New York", "news", "newspaper", "novel", "novella", "nuclear", "obama",
		"obesity", "obsession", "occult", "opera", "orphan", "outer space", "ozark", "pageant", "panel", "paparazzi", "parable", "parade",
		"paranormal", "parent", "parenthood", "parenting", "parents", "Parody", "performance", "period", "photo collage", "photography", "pilot",
		"pirate", "pirates", "plague", "plane", "plane crash", "play", "poetry", "poker", "police", "political", "politics", "pop culture",
		"pornography", "post-apocalyptic", "pot", "poverty", "pregnancy", "pregnant", "prehistoric", "prequel", "president", "prison",
		"private investigator", "procedural", "prostitution", "psa", "psychodrama", "psychological", "psychology", "puppet", "puppets",
		"quest", "race", "race relations", "racing", "racism", "radio", "rags to riches", "rap/hip-hop", "real estate", "redemption", "reggaeton",
		"reincarnation", "relationship", "religion", "religious", "renovation", "repression", "retrospective", "reunion", "revenge", "road",
		"road trip", "robbery", "robot", "rock", "rock 'n' roll", "rock'n'roll", "roll", "romance", "royalty", "roycroft", "running", "rural",
		"santa claus", "satan", "satire", "scandal", "school", "science", "sea", "secrets", "semi-scripted", "sequel", "serial", "serial killer",
		"series", "sex", "shakespeare", "short", "short film", "short stories", "short story", "showbiz", "sibling", "siblings", "silent", "singer",
		"single camera", "sketch", "ski", "skiing", "slasher", "slavery", "small town", "snowboard", "soap opera", "soccer", "softball", "soldier",
		"soviet union", "space", "spinoff", "spin-off", "spoof", "sports", "springsteen", "spy", "stage play", "stand-up", "stand-up comedy", "strip",
		"strip club", "student", "suburban", "suicide", "superhero", "supernatrual", "supernatural", "surfing", "surveillance", "survival", "suspense",
		"symphony", "syndicated", "syndication", "teacher", "technology", "teen", "telenovela", "television", "television series", "tennis", "terror",
		"terrorism", "theater", "tigers", "time travel", "tournament", "toy", "Tragedy", "transformation", "travel", "tree", "tribute", "truck driving",
		"true story", "tsunami", "tv series", "tv show", "tween", "twitter feed", "undercover", "urban", "vacation", "vampire", "vaudeville",
		"video game", "Vietnam War", "vigilante", "viral", "virus", "war", "warrior", "washington dc", "weather", "web", "web series", "website", "wedding",
		"weight loss", "weigth loss", "werewolf", "whodunit", "whodunnit", "wilderness", "work out", "working class", "workplace", "wrestling", "writer",
		"writing", "WWI", "WWII", "zombie"
	];
    function monkeyPatchAutocomplete() {
        $.ui.autocomplete.prototype._renderItem = function (ul, item) {
            item.label = item.label.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(this.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
            return $("<li></li>")
		                    .data("item.autocomplete", item)
		                    .append("<a>" + item.label + "</a>")
		                    .appendTo(ul);
        };
    }
    monkeyPatchAutocomplete();

    $("#select-proj-keyword").autocomplete({
        source: keywords
        //minLength: 2,
    });

});

/*************************************
Common layout functions
*************************************/
//UI display
function uiDisplay() {
    //forms >> disabled inputs on hover
    $("input:disabled").hover(
		function () {
		    $(this).css({ "color": "#ccc", "background": "#eee", "border": "none" });
		}
	);
    // Accordion
    $(".accordion").accordion({ header: "h3" });
    $(".ui-accordian h3.ui-state-default:last-child").css("border-bottom", "none");
    $(".ui-accordian h3.ui-state-hover:last-child").css("border-bottom", "none");
    //tooltip
    $(".tooltip, a.tooltip, input.tooltip").tooltip();
    //Datepicker
    $(".date-pick").datepicker({
        inline: true,
        showOn: 'button',
        buttonImage: '../themes/ih/img/calendar.png',
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true
    });
    //tabs
    $('.tabs').tabs();
    //hover states on the static widgets
    $('#dialog_link, ul#icons li').hover(
		function () { $(this).addClass('ui-state-hover'); },
		function () { $(this).removeClass('ui-state-hover'); }
	);
}
// UI accessibility 
function uiAttr() {
    $("a.dp-choose-date").attr({ title: "Choose date" });
    $(".tool-map a").attr({ title: "Current Mappings for this Record" });
    $(".tool-search a").attr({ title: "Search for Additional Mappings for this Record" });
    $(".tool-notes a").attr({ title: "Notes Archive for this Record" });
    $(".tool-addnotes a").attr({ title: "Add A Note for this Record" });
    $(".tool-flag a").attr({ title: "Add A Flagged Note for this Record" });
    $("a.pc").attr({ title: "View Notes" });
    $("a.pt").attr({ title: "More Changes" });
    $("a.drag-handle").attr({ title: "Drag this handle to move row" });
    $("li.tool-edit a").attr({ title: "Edit current information" });
    $("li.tool-update a").attr({ title: "Update current information" });
    $("li.tool-add a").attr({ title: "Add to current information" });
    $("li.tool-collapse a").attr({ title: "Collapse this section" });
    $("li.pt a").attr({ title: "Edit current information" });
    $("abbr:contains('INC')").attr({ title: "Incomplete" });
    $("abbr:contains('DEL')").attr({ title: "Deleted" });
    $("abbr:contains('ACT')").attr({ title: "Active" });
    $("#c-director a").attr({ title: "Production" });
    $("#c-editor a").attr({ title: "Editing" });
    $("#c-camera a").attr({ title: "Camera, Film, Tape" });
    $("#c-pd a").attr({ title: "Production Design" });
    $("#c-lights a").attr({ title: "Lighting" });
    $("#c-sound a").attr({ title: "Sound" });
    $("#c-anim a").attr({ title: "Visual Effects Animation" });
    $("#c-makeup a").attr({ title: "Wardrobe,Hair,Makeup" });
    $("#c-crewup a").attr({ title: "Crew Up" });
    $("#c-casting a").attr({ title: "Casting Spotlight" });
    $("#c-prod a").attr({ title: "Set Gigs" });
    $("#c-reps a").attr({ title: "Rep Sheet" });
}
//UI advanced css selectors
function uiCssSelect() {
    //structure
    $("article > header:first-child h1").css("padding-top", "0");
    $("#main fieldset:first-child").css("margin-top", "0");
    $("fieldset#promo:first-child").css("margin-top", "20%");
    $("fieldset select.hour").after($("<span>:</span>").css("margin-right", "0.2em"));
    $(".r:last-child").css("margin-bottom", "10em");
    $("label.req").prepend('<span class="req">* </span>');
    $("li span.calendar a").addClass("start");
    $("li span.calendar:last-child a").removeClass("start").addClass("end");
    $(".innerWrap ul.personal ul.category > li:last-child").css("border-bottom", "none");
    $(".category li p.comment-text:not(:last-child)").css("border-bottom", "1px solid #f2f5e9");
    $(".innerWrap ul.personal .personal-row:last-child").css("border-bottom", "none");
    $(".innerWrap > ul li:last-child").css("border-bottom", "none");
    $("#footer ul li:last-child a").css({ "border-right": "none", "padding-right": "0" });
    $("ul.gallery-tn li:nth-child(8n)").css("width", "60px");
	$(".video dd:last-child").css("border-bottom", "none");
    $(".innerWrap #taglist .li_container ol li").mouseover(function () {
        $(this).css("background", "silver");
    }).mouseout(function () {
        $(this).css("background", "#fff");
    });
    //tools
    $(".tl td:first-child").css({ "font-weight": "bold", "font-size": "1.1em" });
    $(".cl td:first-child").css({ "font-weight": "bold", "font-size": "1.1em" });
    $(".tl td:first-child a").css("color", "#6e3209");
    $(".cl td:first-child a").css("color", "#6e3209");
    $("#crew-list li:first-child").css("border-bottom", "none");
    //zebra selectors
    $(".all-notes p:even").addClass("alt");
    $(".section-edu ul:odd").addClass("alt");
    //upsell module		
    $("#acctaccess li p:last-child").css("margin-bottom", "0");
    //detail layout
    $(".s-details > li:last-child").find("dd:last-child").css("border-bottom", "none");
}


// UI css appends
function uiCssAppends() {
    $("span.wrap label:first-child").append(":");
    $("p.time span:first-child").append(":").css("padding-right", "0");
    $("span.checks").append(" ");
    $("span.wrap span.checks label").append(" ");
    $("aside li em").append(":");
    $("aside dt em").append(":");
    $("aside dd em").append(":");
    $(".titlecell").append(":");
}

//UI advanced css selectors in sidebar
function uiAside() {
    $("aside > section h2").addClass("box_shadow");
    $("aside > section.new-m h2").addClass("box_shadow");
    $("aside > #partners > section h2").removeClass("box_shadow");
}
//UI universal non-sorting tables
function uniTbl() {
    $("thead th:last-child").css("border-right", "none");
    $("thead th:first-child").css("border-left", "none");
    //zebra tables
	$("table tbody tr:nth-child(even)").addClass("alt");
    $("table.display tbody tr:nth-child(even)").removeClass("alt");	
    //table hover feedback
    $("table tbody tr").hover(
		  function () {
		      $(this).children().addClass("hover");
		  },
		  function () {
		      $(this).children().removeClass("hover");
		  }
	);
    $("td p > span:first-child").css("padding-right", "0.5em");
	$("td p > span.tool:first-child").css("padding-right", "0");
}
// Search 
function defSearch() {
    $("#ih-searchNav").css("display", "none");
    $('#searchbar').live({
        focus: function () {
            $("#ih-searchNav").css("display", "block");
            $("#searchbar").val('');
            return false;
        },
        click: function () {
            $("#ih-searchNav").css("display", "block");
            $("#searchbar").val('');
            return false;
        }

    });
    $('#ih-searchNav li').live({
        click: function () {
            nosNav();
            $(this).addClass("selected");
            applysearchText();
            return false;
        }
    });
    $("body").bind({
        click: function () {
            $("#ih-searchNav").css("display", "none");
            $("#searchbar").attr('value', 'Search for...');
        }
    });
}

function applysearchText() {
    var sns = $("#ih-searchNav li.selected a").attr('id');
    if (sns == "sr-1") {
        $("#searchbar").attr('value', 'Searching All');
        return false;
    }
    if (sns == "sr-2") {
        $("#searchbar").attr('value', 'Searching for a Person');
        return false;
    }
    if (sns == "sr-3") {
        $("#searchbar").attr('value', 'Searching for Film/TV');
        return false;
    }
    if (sns == "sr-4") {
        $("#searchbar").attr('value', 'Searching for a Company');
        return false;
    }
}
function nosNav() {
    $('#ih-searchNav li').removeClass("selected");
}
//UI search results
function seResult() {
    $(".s > .comment").prepend('<span>Comment:</span>');
    $(".s > .step").prepend('<span>Next Step:</span>');
}
//advanced search
function advSearch() {
    $("#adv-search").css("display", "none");
    $('#site-search').live("click", function () {
        $(this).parents("#adv-search").css("display", "none");
    });

    $('#a-search').live("click", function () {
        $("#adv-search").css("display", "block");
        $(this).parents("section.search-results").css("display", "none");
        return false;
    });
    $('.results').live("click", function () {
        $(this).parents("#adv-search").css("display", "none");
        // $('#adv-search .splist-6').uncolumnlists();
    });
}
//advanced search list	
function advlistSplit() {
    $('#adv-search .splist-6').easyListSplitter({ colNumber: 6 });
}
// section editing tools
// item editing
function editList() {
    $('.toolEdit').bind("click", function () {
        hideItemEditor();
        $(this).addClass("state-active");
        $(this).parents('li').next('.itemeditor').show();
        return false;
    }, function () {
        $(this).parent().parent().parent().next('.itemeditor').hide();
        $(this).removeClass("state-active");
        return false;
    });
}
// item editing update
function editContent() {
    $('.toolUpdate').bind("click", function () {
        //hideItemEditor();
        $(this).addClass("state-active");
        $(this).children("a").addClass("state-active");
        $(this).parents('.content').find('.ucc').show();
        return false;
    });
}
// item editing SYSTEMWATCH
function watchContent() {
    $('.toolWatch').toggle( function () {
        alert("You are now watching this project");
		$(this).find("a").html('<span class="tool tool-watch"></span>' + 'Stop Watching');
	}, function () {
		alert("You are no longer watching this project");
		$(this).find("a").html('<span class="tool tool-watch"></span>' + 'System Watch');
        return false;
    });
}
// item editing email friend
function emailContent() {
    $('.toolEmail').bind("click", function () {
        hideItemEditor();
        $(this).addClass("state-active");
        $(this).children("a").addClass("state-active");
        $(this).parents('.content').find('.eaf').show();
        return false;
    });
}
// item editing add to mylist
function addList() {
    $('.toolList').bind("click", function () {
        hideItemEditor();
        $(this).addClass("state-active");
        $(this).children("a").addClass("state-active");
        $(this).parents('.content').find('.atl').show();
        defaultListOption();
        return false;
    });
}
function defaultListOption() {
    $("#pNewListName").hide();
    $("#pNewListDescription").hide();
    return false;
}
//show fields for new list
function newListOption() {
    $("#ddlExistingList").change(function () {
        var nlo = $("#ddlExistingList option:selected").val();
        if (nlo == "new") {
            $("#pNewListName").show();
            $("#pNewListDescription").show();
        }
    })
}
newListOption();

// item editing Admin add a group
function addGroup() {
    $('.toolGroup').bind("click", function () {
        hideItemEditor();
        $(this).addClass("state-active");
        $(this).children("a").addClass("state-active");
        $(this).parents('.content').find('.agrp').show();
        return false;
    });
}
// item editing Admin add a user
function addUser() {
    $('.toolUser').bind("click", function () {
        hideItemEditor();
        $(this).addClass("state-active");
        $(this).children("a").addClass("state-active");
        $(this).parents('.content').find('.auser').show();
        return false;
    });
}
// item editing Admin new password
function newPW() {
    $('.toolKey').bind("click", function () {
        hideItemEditor();
        $(this).addClass("state-active");
        $(this).children("a").addClass("state-active");
        $(this).parents('.content').find('.apw').show();
        return false;
    });
}
// item editing Admin reset password
function resetPW() {
    $('.a-toolKey').bind("click", function () {
        hideItemEditor();
        $(this).parents('.container').find("#tool-bar").find('.apw').show();
        return false;
    });
}

// item editing View Notes
function viewNotes() {
    $('.toolVnotes').bind("click", function () {
        hideItemEditor();
        $(this).addClass("state-active");
        $(this).children("a").addClass("state-active");
        $(this).parents('.container').find('#tool-bar').children('.vn').show();
        $(".note .footer li span:first-child").css("font-weight", "bold");
        $(".note .footer li:last-child").css("float", "right");
        //goaddNotes();
        return false;
    });
}
function goaddNotes() {
    $.each(".note .footer li a").text("edit").live("click", function () {
        $(this).parents('.vn').hide();
        $(this).parents('.an').show();
        return false;
    });
}
// item editing Add Notes
function addNotes() {
    $('.toolAnotes').bind("click", function () {
        hideItemEditor();
        $(this).addClass("state-active");
        $(this).children("a").addClass("state-active");
        $(this).parents('.container').find('#tool-bar').children('.an').show();
        return false;
    });
}
// item favorite
function itemFav() {
    $('.toolFav').toggle(function () {
        $(this).addClass("state-active");
    }, function () {
        $(this).removeClass("state-active");
    });
}
// close detail itemeditor
function hideItemEditor() {
    $(".itemeditor").hide();
    $('.h-tools li').removeClass("state-active");
    $('.h-tools li a').removeClass("state-active");
}
hideItemEditor();

// item editing subnav
function defaultSubnav() {
    $('.h-tools li ul').css("display", "none");
}
defaultSubnav();
//item editing print page
function printPage() {
    $('.toolPrint a').bind("click", function () {
        window.print();
        return false;
    });
}
printPage();

// close MyLists itemeditor
function closeItemEditor() {
    $(".itemeditor").hide();
}
function toolbarCollapse() {
    //collapse
    $(".toolbar li.tool-collapse a").click(function () {
        $(this).parents(".section").find(".wrapper").toggle();
        if ($(this).hasClass("selected")) {
            defaultSet();
            return false;
        }
        else {
            //defaultSet();
            // add class selected
            $(this).addClass("selected");
        }
    });
    $(".head li.tool-collapse a").click(function () {
        $(this).parents(".wrapper").find(".innerWrap").toggle();
        if ($(this).hasClass("selected")) {
            defaultSet();
            return false;
        }
        else {
            //defaultSet();
            // add class selected
            $(this).addClass("selected");
        }
    });
    function defaultSet() {
        $("li.tool-collapse a").removeClass("selected");
    }
}
// module header toolbar tools
function modTool() {
    $('.toolbar li').addClass('state-default');
    //init each tool
    editList();
    editContent();
    emailContent();
    addList();
    watchContent();
    toolbarCollapse();
    viewNotes();
    addNotes();
    //tool hover
    $('.toolbar li').bind({
        mouseenter: function () {
            $(this).addClass('state-hover');
            $(this).children('ul').css("display", "block");
        },
        mouseleave: function () {
            $(this).removeClass('state-hover');
            $(this).children('ul').css("display", "none");
        }
    });
    //itemeditor close button
    $('.toolClose a').live("click", function () {
        hideItemEditor();
        $(this).parents('.content').find('.h-tools li').removeClass('state-active');
        $(this).parents('.content').find('.h-tools li a').removeClass('state-active');
    });
    //detail layout itemeditor submits
    $('.content > .itemeditor .results').live("click", function () {
        hideItemEditor();
        $(this).parents('.content').find('.h-tools li').removeClass('state-active');
        $(this).parents('.content').find('.h-tools li a').removeClass('state-active');
    });
    $('.content > .itemeditor .toolClose').live("click", function () {
        hideItemEditor();
        $(this).parents('.content').find('.h-tools li').removeClass('state-active');
        $(this).parents('.content').find('.h-tools li a').removeClass('state-active');
    });

    //My Lists submit
    $('.t li.itemeditor .results').live("click", function () {
        closeItemEditor();
        $(this).parents('li.itemeditor').prev('li').find('.h-tools li').removeClass('state-active');
    });
}


//bio text			
function defaultBio() {
    $('.bio-text .show-bio').css("display", "block");
    $(".bio-text").addClass("abstract");
    $('.abstract .show-bio').html('Show Full Bio').css("display", "block");
    $('.bio-abstract').css("display", "block");
    $('.bio-complete').css("display", "none");

    $('.abstract .show-bio').live({
        click: function () {
            $(this).parent(".bio-text").removeClass("abstract").addClass("fullbio");
            $(this).html('Show Abstract');
            changeBio();
            return false;
        }
    });
}
function changeBio() {
    $('.bio-complete').css("display", "block");
    $('.bio-abstract').css("display", "none");
    $('.fullbio .show-bio').live({
        click: function () {
            $(this).parent(".bio-text").removeClass("fullbio").addClass("abstract");
            $(this).html('Show Full Bio');
            defaultBio();
            return false;
        }
    });

}
//bio layout
function bioInner() {
    $(".biodoc").css({ "text-indent": "2em", "line-height": "1.5" });
}

// modal - register now
function nowReg() {
    $('#ureg').dialog('close');
    $(function () {
        $("#ureg").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 320,
            width: 540,
            resizable: false,
            modal: true,
            dialogClass: 'register',
            zIndex: 3200,
            overlay: {
                backgroundColor: '#000',
                opacity: 0.4
            },
            title: 'Login or Register'
        });

        $(".openreg").click(function () {
            $('#ureg').dialog('open');
        });
        $("#ureg .modalClose, #ureg .ui-icon-closethick, .ui-icon-closethick").click(function () {
            $('#ureg').dialog('close');
        });
    });
}
// section collapse
function nowReg() {
	$(".toolbar li.tool-collapse a").click( function () {
		$(this).parents(".section").find(".wrapper").toggle();
		if($(this).hasClass("selected")) {
	            defaultSet();
	                    return false;
	        }
	        else {
	            //defaultSet();
	            // add class selected
	            $(this).addClass("selected");
	         }
	 });
}
/*************************************
wireframe specific structure functions are below
*************************************/

//site header
function siteHeader() {
    if (typeof dev != 'undefined') {  
		
		var sh = $("#hd").attr('class');
	    if (sh == "container") {
	        $.ajax({
	            url: 'inc/site-header.html',
	            dataType: 'html',
	            success: function (data) {
	                $('#hd header').append(innerShiv(data));
	            }
	        });
	    }
	    if (sh == "container hdlogin") {
	        $.ajax({
	            url: 'inc/site-header-login.html',
	            dataType: 'html',
	            success: function (data) {
	                $('#hd header').append(innerShiv(data));
	                advSearch();
	                nowReg();
	            }
	        });
	    }
	    if (sh == "container hdsearch") {
	        $.ajax({
	            url: 'inc/site-header-search.html',
	            dataType: 'html',
	            success: function (data) {
	                $('#hd header').append(innerShiv(data));
	            }
	        });
	    } 
		
	}else {
		var sh = $("#hd").attr('class');
		 if (sh == "container hdlogin") {
			 advSearch();
             nowReg()
		 }
	}

}

//sitenavigation
function siteNavigate() {
    var bclass = $("body");
    if ((bclass).hasClass("dash")) {
        defaultsiteNav();
        $("ul.main li#mDash").addClass('selected');
    }
    if ((bclass).hasClass("advSearch")) {
        defaultsiteNav();
        $("ul.main li#mAdvsearch").addClass('selected');
    }
    if ((bclass).hasClass("advResults")) {
        defaultsiteNav();
        $("ul.main li#mResults").addClass('selected');
    }
    if ((bclass).hasClass("mysearch")) {
        defaultsiteNav();
        $("ul.main li#mSearch").addClass('selected');
    }
    if ((bclass).hasClass("mylist")) {
        defaultsiteNav();
        $("ul.main li#mList").addClass('selected');
    }
    if ((bclass).hasClass("mylist")) {
        defaultsiteNav();
        $("ul.main li#mList").addClass('selected');
    }
    if ((bclass).hasClass("mynote")) {
        defaultsiteNav();
        $("ul.main li#mNote").addClass('selected');
    }
    if ((bclass).hasClass("myacct")) {
        defaultsiteNav();
        $("ul.main li#mAcct").addClass('selected');
    }
    if ((bclass).hasClass("cal")) {
        defaultsiteNav();
        $("ul.main li#mCal").addClass('selected');
    }
    if ((bclass).hasClass("calsort")) {
        defaultsiteNav();
        $("ul.main li#mCal").addClass('selected');
    }
    if ((bclass).hasClass("help")) {
        defaultsiteNav();
        $("ul.main li#mHelp").addClass('selected');
    }
    if ((bclass).hasClass("admin")) {
        defaultsiteNav();
        $("ul.main li#mAdmin").addClass('selected');
    }

    function defaultsiteNav() {
        $("ul.main li").removeClass("selected");
    }
}

function siteMainav() {
    if (typeof dev != 'undefined') {   
		$.ajax({
		        url: 'inc/site-main-nav.html',
		        dataType: 'html',
		        success: function (data) {
		            $('#hd nav').html(innerShiv(data));
		            sizeMenuitem();
		            siteNavigate();
		            $("ul.main li:last-child").css("border-right", "none");
		        }
		 });
	}else {
		sizeMenuitem();
	    siteNavigate();
	    $("ul.main li:last-child").css("border-right", "none");
	}
}
function sizeMenuitem() {
    var total = 0;
    $('ul.main > li').each(function () {
        total += $(this).width() + 2;
    });
    var num_li = $('ul.main > li').size();
    var extra_space = (parseInt($('ul.main').width()) - total) / num_li;

    $('ul.main > li').each(function () {
        $(this).width($(this).width() + Math.floor(extra_space));
    });
}

//site footer
function sFoot() {
    if (typeof dev != 'undefined') { 
	    $.ajax({
	        url: 'inc/site-footer.html',
	        dataType: 'html',
	        success: function (data) {
	            $('#main').after(innerShiv(data));
	            $("#footer nav li:last-child a").css("border-right", "none");
	        }
	    });
	}else {
		$("#footer nav li:last-child a").css("border-right", "none");
	}

}
//gallery list
function tnGallery() {
    if (typeof dev != 'undefined') { 
	    $.ajax({
	        url: 'inc/mm-gal-tn.html',
	        dataType: 'html',
	        success: function (data) {
	            $('#gallery-list #mm-img header').after(innerShiv(data));
	        }
	    });
	}else {
				
	}
}
//single gallery image list
function tnImg() {
    if (typeof dev != 'undefined') { 
	    $.ajax({
	        url: 'inc/mm-img-tn.html',
	        dataType: 'html',
	        success: function (data) {
	            $('#image-list .g-feature').after(innerShiv(data));
	        }
	    });
	}else {
				
	}
}
