﻿
/// <reference path="jquery-1.4.1-vsdoc.js" />

// Site-wide JavaScript namespace
var pella = {};


/** GLOBAL CLEANUP *******************************************/
$(function() {
	// Prevent blank hyperlinks from navigating
	$("a[href=''],a[href='#']").click(function(e) {
		e.preventDefault();
		this.blur();
	});
});

/** PNG fix for IE 5.5 & 6 ********************************
    $(document).ready(function(){ 
        $(document).pngFix(); 
    }); 
*/
/** /MY-PELLA: Hide secondary nav *********************************/
$(function(){
    if ( (window.location.href).match("/my-pella") || 
         (window.location.href).match("search/default") ||
         (window.location.href).match("location/where-to-buy/default")
       )  
    {
        $('.section02 .box02').remove();
    }
    
	$('.printLink').click(function() {
        window.print();
	});

});

/** SEND | PRINT | SHARE (AddThis.com) ***********/
// On click event
function shareIt(site) { 
    var metaArray = document.getElementsByName('description');
        for (var i=0; i<metaArray.length; i++) {
            var d = metaArray[i].content;
        }
    var t = document.title; // page title
    var l = document.location; // page url
    var s = site.toLowerCase();
    var u = 'http://www.' + s + '.com/'; //URL
    switch (s) {
        //case 'twitter':     u += 'home?status=' + t; break;
        case 'twitter':     u += 'home?status=' + l; break;
        case 'facebook':    u += 'sharer.php?u=' + l; break;
        case 'myspace':     u += 'Modules/PostTo/Pages/?t=' + t + '&c=' + d + '&u=' + l + '&l=2'; break;
        case 'stumbleupon': u += 'submit?url=' + l + '&title=' + t; break;
        case 'digg':        u += 'submit?phase=2&url=' + l + '&title=' + t; break;
    }
    window.open(u); 
}
// Populate <div class=shareThis></div>
$(function(){
    if ($('.supportLinks')) {
        // SEND
        var sendCode = "";
            sendCode = "<a id='AEmailLightboxLink' href='Javascript:void(0);'>";
            sendCode += "<img src='/_layouts/1033/pella/images/mail_icon.png' border='0' width='18' height='13' alt='Send' />";
            sendCode += "Send";
            sendCode += "</a>";
        $('.sendDiv').html (sendCode);

        // PRINT
        var printCode = "";
            printCode = "<a href='#' id='printButton'>";
            printCode += "<img src='/_layouts/1033/pella/images/print_icon.png' border='0' width='18' height='13' alt='Print' />";
            printCode += "Print";
            printCode += "</a>";
        $('.printDiv').html (printCode);

        var shareCodeLocation = window.location.pathname + location.search; 
      
        // SHARE (Original method, using addThis.com)
        var shareCode = "";
            shareCode = "<div class='addthis_toolbox'>";
                shareCode += "<div class='custom_hover'><div class='custom_button'>Share</div></div>";
                shareCode += "<div class='hover_menu'>";
                    shareCode += "<div class='clear'></div>";
                    shareCode += "<div class='top'></div>";
                    shareCode += "<div class='column1'>";
                        shareCode += "<a class='addthis_button_twitter' onclick=\"pageTracker._trackPageview('/tools/share/twitter" + shareCodeLocation +"');\" >Twitter</a>";
                        shareCode += "<a class='addthis_button_facebook'  onclick=\"pageTracker._trackPageview('/tools/share/facebook" + shareCodeLocation +"');\" >Facebook</a>";
                        shareCode += "<a class='addthis_button_myspace'  onclick=\"pageTracker._trackPageview('/tools/share/myspace" + shareCodeLocation +"');\" >MySpace</a>";
                        shareCode += "<a class='addthis_button_stumbleupon'  onclick=\"pageTracker._trackPageview('/tools/share/stumbleupon" + shareCodeLocation +"');\" >Stumble</a>";
                        shareCode += "<a class='addthis_button_digg'  onclick=\"pageTracker._trackPageview('/tools/share/digg" + shareCodeLocation +"');\" >Digg</a>";
                    shareCode += "</div>";
                    shareCode += "<div class='more'><a class='addthis_button_expanded'>More Destinations</a></div>";
                shareCode += "</div>";
            shareCode += "</div>";
        $('.shareDiv').html (shareCode);

        // NEW METHOD, June 2010 (<div class=shareThis>)
        // create array, then an <li> for each word within <div class=shareThis></div>
        var sites = ($('div.shareThis').text());
        arr = sites.split(" ");
        var listCode = '';
        $.each(arr, function(){
            listCode += "<li><a href=javascript:shareIt('"+this+"'); title=Share this on "+this+" class="+this.toLowerCase()+">"+this+"</a></li>";
        });
        
        // Build the dropdown list using jquery.dropdownPlain.js
        var shareThis = "";
            shareThis = "<ul class='dropdown'>";
                shareThis += "<li><a href='#'>Share</a>";
                    shareThis += "<ul class='sub_menu'>";
                        shareThis += listCode;
                    shareThis += "</ul>";
                shareThis += "</li>";
            shareThis += "</ul>";
        $('.shareThis').html(shareThis);
    }
    // Hover menu
    $('.custom_button, .hover_menu').mouseenter(function()
    {
        $('.hover_menu').fadeIn('fast');
        $('.custom_button').addClass('active');
        $(this).data('in', true);
        $('.hover_menu').data('hidden', false);
    }).mouseleave(function()
    {
        $(this).data('in', false);
        setTimeout(hideMenu, delay);
    });    
    var delay = 400;
    function hideMenu()
    {
        if (!$('.custom_button').data('in') && !$('.hover_menu').data('in') && !$('.hover_menu').data('hidden'))
        {
            $('.hover_menu').fadeOut('fast');
            $('.custom_button').removeClass('active');
            $('.hover_menu').data('hidden', true);
        }
    }
});
// jquery.dropdownPlain.js:
$(function(){
    $("ul.dropdown li").hover(function(){
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }, function(){
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    });
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
});

/** SMART SEARCH *******************************************/
$(function() { pella.ss.init(); });

pella.ss = {

    // Smart Search constants
    strings: {
        REQUEST_URL: "/_catalogs/masterpage/utils/smartsearch.aspx",
        REDIRECT_URL: "/_catalogs/masterpage/utils/searchredirect.aspx",
        ALL_RESULTS_URL: "/search/default.aspx",
        THUMBNAILS_BASE_URL: "/_layouts/1033/pella/images/smartsearch/",
        EMPTY_SUBMISSION_ALERT: "Enter keyword",
        ALL_RESULTS_ACTION_BUTTON: "View All Results",
        NO_RESULTS_ACTION_BUTTON: "No shortcut found. Try a full search of Pella.com"
    },

    // These properties are not configurable; they are assigned in init()
    label: "",
    query: "",
    totalResults: 0,
    selectedIndex: -1,
    box: null,
    resultsDiv: null,
    closeButton: null,
    xhr: null,

    // Sets up event handlers and initial values for the Smart Search
    init: function() {
        pella.ss.box = $("#TxtSearchText");
        pella.ss.resultsDiv = $("#DivSSContainer");

        // Position the Smart Search Results div
        var headerDiv = $("div.box03:first");
        var resultsLeftOffset = (headerDiv.outerWidth() - pella.ss.resultsDiv.outerWidth()) + 3;
        pella.ss.resultsDiv.css({ "top": headerDiv.innerHeight() + "px", "left": resultsLeftOffset + "px" });

        // Create and position the "close" button
        var closeBtnVerticalOffset = parseInt(pella.ss.box.innerHeight() / 2) - 4 // + 2;
        var closeBtnTop = pella.ss.box.position().top + closeBtnVerticalOffset;
        var closeBtnLeft = (pella.ss.box.position().left + pella.ss.box.innerWidth()) - 15 // - 50;
        pella.ss.closeButton = $("<img/>")
			.attr("src", "/_layouts/1033/pella/images/search_close.gif")
			.attr("id", "ImgSSCloseButton")
			.css({ "top": closeBtnTop, "left": closeBtnLeft })
			.click(function() {
			    pella.ss.box.val("");
			    pella.ss.resetResultsBox();
			})
			.appendTo(headerDiv);

        // Dismiss Smart Search results on blur
        $("body").click(function(e) {
            if ($(e.target).parents("#DivSSContainer").length == 0 && !$(e.target).is("#TxtSearchText")) pella.ss.resetResultsBox();
        });

        // Remove search box label and insert it inline
        pella.ss.label = $("label[for=TxtSearchText]").remove().text();
        pella.ss.box
			.val(pella.ss.label)
			.focus(function(e) { if ($(this).val() == pella.ss.label || $(this).val() == pella.ss.strings.EMPTY_SUBMISSION_ALERT) $(this).val(""); })
			.blur(function(e) { if ($(this).val() == "") $(this).val(pella.ss.label); });

        // Initiate the Smart Search after a key is pressed
        pella.ss.box.keyup(function(e) {
            pella.ss.getResults(e);
        });

        // Up/down keys sometimes move cursor in text box. They should not.
        pella.ss.box.keydown(function(e) {
            if (e.keyCode == 38 || e.keyCode == 40) return false;
            else return true;
        });

        // Enter key triggers submit on keypress
        pella.ss.box.keypress(function(e) {
            if (e.keyCode == 13) {	// Enter key == 13
                if (pella.ss.selectedIndex > -1 && pella.ss.selectedIndex < pella.ss.totalResults) {
                    pageTracker._trackPageview('/tools/smartsearch/' + escape(pella.ss.query));
                    location = $("div.ssResult:not(#DivSSResultTemplate):eq(" + pella.ss.selectedIndex + ")").data("link");
                    return false;
                } else $("#BtnSearchSubmit").click();
            }
        });

        // Do not allow form submit w/ empty search terms
        $("#BtnSearchSubmit").click(function(e) {
            return pella.ss.disallowBlankSubmission();
        });
    },

    // Fetches keyword results via AJAX
    getResults: function(e) {
        // Only kick off a new query if the term has been modified
        var newQuery = false;
        if (pella.ss.query != pella.ss.box.val()) {
            newQuery = true;
            pella.ss.query = pella.ss.box.val();
        }

        if (e.keyCode == 38 || e.keyCode == 40) {	// Up arrow == 38, down arrow == 40
            var moveBy = (e.keyCode == 38) ? -1 : 1;

            $("div.ssResult").removeClass("over");
            pella.ss.selectedIndex += moveBy;

            if (pella.ss.selectedIndex < -1) {
                // Wrap back around
                pella.ss.selectedIndex = pella.ss.totalResults - 1;
            }

            if (pella.ss.selectedIndex >= pella.ss.totalResults) {
                // Wrap back around
                pella.ss.selectedIndex = -1;
            } else if (pella.ss.selectedIndex > -1) {
                // Select the next/previous result by index
                $("div.ssResult:not(#DivSSResultTemplate):eq(" + pella.ss.selectedIndex + ")").addClass("over");
            }
        } else if (pella.ss.query.length == 0) {
            // Cancel any AJAX calls currently in progress
            if (pella.ss.xhr) pella.ss.xhr.abort();

            pella.ss.resetResultsBox();
            //} else if (e.keyCode == 8 || e.keyCode == 46 || e.keyCode >= 59) {	// Backspace key == 8, delete key == 46 (or character key)
        } else if (newQuery) {

            // Cancel any AJAX calls currently in progress
            //##TODO fix for IE7 -- not absolutely required, just a nice-to-have
            try { if (pella.ss.xhr) pella.ss.xhr.abort(); }
            catch (e) { }

            // Kick off new AJAX call
            pella.ss.xhr = $.ajax({
                url: pella.ss.strings.REQUEST_URL,
                type: "get",
                data: {
                    q: pella.ss.query,
                    from_page: location.pathname
                },
                beforeSend: function(req) {
                    // Indicate lookup status
                    pella.ss.box.addClass("wait");
                    pella.ss.closeButton.hide();
                },
                error: function(req, status, er) {
                    // Fail silently; default to Site Search
                    pella.ss.resetResultsBox();
                },
                success: function(xml, status, req) {
                    if ($("search", xml).length > 0) {
                        pella.ss.updateResults(xml);
                    } else {
                        // Fail silently; default to Site Search
                        pella.ss.resetResultsBox();
                    }
                },
                complete: function(req, status) {
                    // Indicate lookup status
                    pella.ss.box.removeClass("wait");

                    // discard the reference to the request
                    pella.ss.xhr = null;
                }
            });
        }
    },

    // Clone the appropriate containers in the results div and inserts values from the XML
    updateResults: function(xml) {
        pella.ss.totalResults = $("search_results>match", xml).length;
        pella.ss.selectedIndex = -1;

        var term = $("term", xml).text();
        var termMatched = $("term_matched", xml).text();
        var queryId = $("query_id", xml).text();
        var userId = $("user_id", xml).text();

        // View All Results button passes on information about the Smart Search results
        $("#BtnSSViewAll").unbind("click").bind("click", function(e) {
            e.preventDefault();
            var allResultsLink = pella.ss.strings.ALL_RESULTS_URL + "?"
				+ "user_id=" + userId + "&"
				+ "term=" + term + "&"
				+ "term_matched=" + termMatched + "&"
				+ "query_id=" + queryId + "&"
				+ "q=" + term;
            location = allResultsLink;
        });

        if (pella.ss.totalResults > 0) {
            var category, thumbnail, title, url, description;
            var curCategory, curCategoryDiv;
            var resultDiv;
            var index = 0;

            pella.ss.resetResultsBox();

            $("search_results>match", xml).each(function(i) {
                category = $(this).attr("PageCategory");
                thumbnail = $(this).attr("ImageURL");
                title = $(this).attr("PageName");
                url = $(this).attr("PageURL");
                url = escape(url);
                description = $(this).attr("Description");

                var redirectLink = pella.ss.strings.REDIRECT_URL + "?"
					+ "url=" + url + "&"
					+ "user_id=" + userId + "&"
					+ "term=" + term + "&"
					+ "term_matched=" + termMatched + "&"
					+ "query_id=" + queryId + "&"
					+ "from_page=" + location.pathname;

                if (category != curCategory) {
                    // Make a new Category div and add it to the results div
                    curCategoryDiv = $("#DivSSCategoryTemplate").clone().removeAttr("id").insertBefore("#BtnSSViewAll");
                    $("div.ssCatHeading", curCategoryDiv).text(category);
                    curCategory = category;
                }

                // Make a new result item div w/ event handlers
                resultDiv = $("#DivSSResultTemplate", curCategoryDiv).clone()
					.removeAttr("id")
					.appendTo(curCategoryDiv)
					.data("index", index)
					.data("link", redirectLink)
					.hover(
						function() {
						    $("div.ssResult").removeClass("over");
						    $(this).addClass("over");
						    pella.ss.selectedIndex = $(this).data("index");
						},
						function() {
						    // Retain on state onmouseout; this allows the user to toggle between mouse input and arrow/enter keys
						}
					)
					.click(function() {
					    pageTracker._trackPageview('/tools/smartsearch/' + escape(pella.ss.query));
					    location = redirectLink;
					});

                // Fill in values from the XML
                $("img.ssThumbnail", resultDiv).attr("src", pella.ss.strings.THUMBNAILS_BASE_URL + thumbnail);
                $("h4.ssResultTitle", resultDiv).html(title);
                $("p.ssResultDescription", resultDiv).html(description);

                index++;
            });

            $("#BtnSSViewAll").val(pella.ss.strings.ALL_RESULTS_ACTION_BUTTON);
            pella.ss.resultsDiv.show();
            pella.ss.closeButton.show();
        } else {
            // No results found. Remove all results from the results div and update the "View All" messaging.
            pella.ss.resetResultsBox();
            $("div.ssResult:not(#DivSSResultTemplate)").remove();
            $("div.ssCategory:not(#DivSSCategoryTemplate)").remove();
            $("#BtnSSViewAll").val(pella.ss.strings.NO_RESULTS_ACTION_BUTTON);
            pella.ss.resultsDiv.show();
            pella.ss.closeButton.show();
        }
    },

    // Resets the interface back to its initial state
    resetResultsBox: function() {
        pella.ss.box.removeClass("wait");
        pella.ss.closeButton.hide();
        $("div.ssCategory:not(#DivSSCategoryTemplate)").remove();
        pella.ss.resultsDiv.hide();
    },

    // Returns true if the search box contains a valid query
    disallowBlankSubmission: function() {
        var trimmed = pella.ss.box.val().replace(/^\s*/, '').replace(/\s*$/, '');
        switch (trimmed) {
            case "":
            case pella.ss.label:
            case pella.ss.strings.EMPTY_SUBMISSION_ALERT:
                pella.ss.box.val(pella.ss.strings.EMPTY_SUBMISSION_ALERT);
                return false;
                break;
            default:
                return true;
                break;
        }
    }
};



/* SEARCH RESULTS *******************************************/
$(function() {
	// Enter key triggers submit on keypress
	$("#TxtSearchTextInline").keypress(function(e) {
		if (e.keyCode == 13) {	// Enter key == 13
		    pageTracker._trackPageview('/tools/smartsearch/' + $("#TxtSearchText").value);
			$("#BtnSearchSubmitInline").click();
		}
	});
});



/* LIGHTBOX (zBox) *******************************************/
$(function() { pella.zb.init(); });
pella.zb = {
	
	params: {
		bgcolor: "#ffffff", 
        allowScriptAccess: "always"
	},
	width: 640,
	height: 382,
	flash: null,
	
	init: function() {
		// Crawl the DOM and look for lightbox links
		$("a.zBoxLink").each(function(i) {
			
			var id = $(this).attr("id");
			id = id.substr(id.indexOf("_")+1);
			
			// Initialize the lightbox
			zBox_CreateBox(id);
			
			// Show lightbox on click
			$(this).click(function(e) {
				e.preventDefault();
				zBox_GetBox(id).Show();
				
			});
		});
		
		// Close button: hide visible lightbox
		$("div.zboxText").click(function(e) {
			zBox_GetVisibleBox().Hide();
		});
	}
};




/* VIDEO PLAYER (zBox) *******************************************/
$(function() { pella.vp.init(); });
pella.vp = {
	
	params: {
		bgcolor: "#ffffff", 
        allowScriptAccess: "always"
	},
	width: 640,
	height: 382,
	flash: null,
	
	init: function() {
		// Crawl the DOM and look for video player lightboxes
		$("a.video-thumbnail").each(function(i) {
			
			var id = $(this).attr("id");
			id = id.substr(id.indexOf("-") + 1);
			
			var flv = $(this).attr("href");
			
			// Initialize the lightbox
			zBox_CreateBox("DivVideoLightbox-" + id);
			
			// Add the swfObject
			var attributes = { id: "video" + id };
			var flashvars = { video: flv };
			pella.trace.log(flv);
			swfobject.embedSWF(
				"/_layouts/1033/pella/Flash/videoplayer.swf", 
				"DivVideoSwf-" + id, 
				pella.vp.width, 
				pella.vp.height, 
				"9.0.0", 
				"/_layouts/1033/pella/Flash/expressInstall.swf", 
				flashvars, 
				pella.vp.params, 
				attributes
			);
			
			// Show lightbox on click and play video
			$(this).click(function(e) {
				e.preventDefault();
				zBox_GetBox('DivVideoLightbox-' + id).Show();
				
				// Pause briefly to assure that the div is visible before attempting to play
				setTimeout(function(){$("#video" + id).get(0).sendTextToFlash("play");}, 500);
			});
		});
		
		// Close button: hide visible lightbox & stop playing
		$("a.close", "div.video.zbox").click(function(e) {
			e.preventDefault();
			
			var id = $(this).parents("div.video.zbox").attr("id");
			id = id.substr(id.indexOf("-") + 1);
			$("#video" + id).get(0).sendTextToFlash("pause");
			
			zBox_GetVisibleBox().Hide();
		});
	}
};



/* NAV ROLLOVERS *******************************************/
$(function() { pella.rollover.init(); });
pella.rollover = {
	init: function() {
		this.preload();
		$(".ro").hover(
			function () { $(this).attr( 'src', pella.rollover.newimage($(this).attr('src')) ); },
			function () { $(this).attr( 'src', pella.rollover.oldimage($(this).attr('src')) ); }
		);
	},
	preload: function() {
		$(window).bind('load', function() {
			$('.ro').each( function( key, elm ) { $('<img>').attr( 'src', pella.rollover.newimage( $(this).attr('src') ) ); });
		});
	},
	newimage: function( src ) { return src.substring( 0, src.search(/(\.+)/) ) + '_over' + src.match(/(\.[a-z]+)/)[0]; },
	oldimage: function( src ) { return src.replace(/_over/, ''); }
};

/* DEBUGGING *******************************************/
$(function() { pella.trace.init(); });

pella.trace = {
	enabled: true,
	builtin: (typeof console != "undefined"),
	init: function() {
		if (pella.trace.enabled && !pella.trace.builtin) {
			$("<div/>").attr("id", "outputTrace").append("<div><span>X</span></div>").append("<ol/>").appendTo("body").hide();
			$("#outputTrace>div>span").click(function(e) {
				$("#outputTrace").hide();
			});
		}
	},
	log: function(msg) {
		if (pella.trace.enabled) {
			if (pella.trace.builtin) console.log(msg);
			else {
				var log = $("#outputTrace").show();
				$("ol", log).append("<li>" + msg + "</li>");
			}
		}
	}
}
	  
/* FROM EXPANDCOLLAPSE.JS *******************************************/

// Create the tooltips only on document load
$(document).ready(function() 
{
	$("a#opt01-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt02-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt03-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt04-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt05-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt06-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt07-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt08-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt09-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt010-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt011-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt012-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt013-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt014-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt015-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt016-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt017-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt018-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt019-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	$("a#opt020-toggle").click(function () {
	  $(this).toggleClass("option-active");
	});
	
		
	$('a#opt01-toggle').click(function() {
    	$('#opt01').slideToggle(20);
    	bottomBorder($(this));
    	return false;
    });
	$('a#opt02-toggle').click(function() {
    	$('#opt02').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
	$('a#opt03-toggle').click(function() {
    	$('#opt03').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt04-toggle').click(function() {
	    $('#opt04').slideToggle(20);
    	bottomBorder($(this));
        return false;
    });
	 $('a#opt05-toggle').click(function() {
    	$('#opt05').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
	$('a#opt06-toggle').click(function() {
	    $('#opt06').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
	$('a#opt07-toggle').click(function() {
	    $('#opt07').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
	$('a#opt08-toggle').click(function() {
	    $('#opt08').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
	$('a#opt09-toggle').click(function() {
	    $('#opt09').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt010-toggle').click(function() {
	    $('#opt010').slideToggle(20);
    	bottomBorder($(this));
        return false;
    });
    $('a#opt011-toggle').click(function() {
        $('#opt011').slideToggle(20);
    	bottomBorder($(this));
        return false;
    });
	$('a#opt012-toggle').click(function() {
	    $('#opt012').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt013-toggle').click(function() {
	    $('#opt013').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt014-toggle').click(function() {
	    $('#opt014').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt015-toggle').click(function() {
	    $('#opt015').slideToggle(20);
    	bottomBorder($(this));
        return false;
    });
    $('a#opt016-toggle').click(function() {
	    $('#opt016').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt017-toggle').click(function() {
	    $('#opt017').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt018-toggle').click(function() {
	    $('#opt018').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt019-toggle').click(function() {
	    $('#opt019').slideToggle(20);
    	bottomBorder($(this));
	    return false;
    });
    $('a#opt020-toggle').click(function() {
	    $('#opt020').slideToggle(20);
    	bottomBorder();
	    return false;
    });

});

function bottomBorder(th) {
    // Hide the bottom border when open
    th.parent().toggleClass("bottomBorder");
};

/* GET QUERY STRING VALUES *******************************************/
/* (/XSLT/windows/explore-window-styles/windowdetails.xslt) */

function getQuerystring(key, default_) {
    if (default_==null) default_="";
    key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if(qs == null)
    return default_;
    else
    return qs[1];
}

/** PRINT BUTTON *******************************************/
$(function(){
	$('#printButton').click(function() {
        if ((window.location.href).match("aspx?")) {
	        window.open(this.href+'&print=yes');
	    } else {
	        window.open(this.href+'?print=yes');
	    }
	})
	// Apply print css to new window
    if ((window.location.href).match("&print")) {
        var currCSS = document.getElementById('ctl00_printCSS');
    	if(currCSS.media == 'screen'){
            currCSS.media = 'print';
            }
        else { 
        currCSS.media = 'screen';
        }
      window.print();
    }
});

/*  */

