// Leave $ namespace alone
jQuery.noConflict();

// shorthand for document.ready
jQuery(function($) { // $ == jQuery in this block
	
	// Used for image loading/preloading
	$.images = {
		path: '/_images/', // path to images
		folders: {}
	};
	
	$('body')
	
	$('#primary')
		.find('dl.faqs').make_faqs().end();	// setup faqs
		
	$spanLeft = $('<span class="borderLeft"></span>');
	$spanRight = $('<span class="borderRight"></span>')
	$('div#header').prepend($spanLeft).prepend($spanRight);
	
	$spanBody = $('<span class="bodyShadow"></span>');
	$('div#body').prepend($spanBody);
    
	    headertxt = ''+
    '<span id="logo"><a href="http://www.protection1.com/" title="Protection 1: Your home and business security provider with customized security solutions">Protection 1 – Home and Business Security</a></span>'+
		'<ul id="links" style="top: 6px">'+
			'<li><a onclick="window.open(\'http://www.protection1.com/global/pop-chat.shtml\',\'chat\',\'height=320,width=470\');" href="javascript:void(0)"><span style="color:#b40a37">Live Chat</span></a></li>'+
			'<li><a href="http://www.protection1.com/global/customer_support.shtml">Customer Support</a></li>'+
			'<li class="last"><a href="http://www.protection1.com/global/local_branches.shtml">Branch Locator</a></li>'+
		'</ul>'+
		'<ul id="helpLinks">' +
			'<li class="chat">FREE Estimate <a href="tel:866-687-3778">866.687.3778</a></li>'+
			'<li class="num">Customer Service <a href="tel:877-776-1911">877.776.1911</a></li>'+
		'</ul>'+
		'<div align="right" style="position: absolute; top: 60px; right: 27px;"><h3 style="margin: 3px 0px 5px 5px;float:left">Your Account <a onclick="window.open(\'/global/what_service.html\',\'service\',\'height=450,width=415\');" href="javascript:void(0)"><img src="/_images/sign_on_help.jpg" width="16" height="16" alt="Protection 1 Sign On for Security Account Help" /></a></h3>' +
		'<form name="Jump" style="margin:0px;padding:0px;float:left" method="post" action="javascript:jumpJumpMenu();">'+
		'<select id="" style="margin: 3px 0px 5px 5px; vertical-align: top; float:left; padding:0; font-size:100%; width:160px;" size="1" name="menu">' +
        	'<option value="#">Choose One...</option>'+
            '<option value="https://services.alarmnet.com/P1Connect">e-Secure Web & Mobile</option>'+
            '<option value="https://www.protection1.com/eSuite">eSuite</option>'+
            '<option value="https://www.protectiononeaccess.com/">Online Access</option>'+
            '<option value="https://secure3.i-doxs.net/ProtectionOne/">Online Bill Payment</option>'+
			/*'<option value="/bill_payment_message.shtml">Online Bill Payment</option>'+*/
            '<option value="https://sso.brivo.com/sso/page/?brand=pro1">Secure Access — Brivo</option>'+
			'<option value="https://www.protection1.com/secureaccess">Secure Access — WINPAK</option>'+
	    '</select>'+
	    '<input style="padding-left: 5px;" type="image" src="/_images/go_button_home.png" width="43" height="27" />'+
    '</form></div>';
    
    nav0txt = ''+
	'<a name="navigation" id="navigation">Site Navigation</a>'+
		'<ul>'+
			'<li><a href="/wireless-home-security-systems.shtml" id="resLink">Residential</a></li>'+
			'<li><a href="/wireless-security-camera-systems-for-businesses.shtml" id="busLink">Business</a></li>'+
		'</ul>';
    
    nav1txt = ''+
	'<ul class="res">'+
		'<li><a href="https://www.protection1.com/residential/request_evaluation.aspx">FREE Home Security Evaluation</a>'+
        '</li>'+    
		'<li><a href="/residential/home-alarms.shtml">Why Protection 1?</a>'+
        '</li>'+
		'<li><a href="/home-security-systems-and-products.shtml">Home Security Products</a>'+
			'<ul id="res_productsGroup">'+
				'<li><a href="/residential/Security-Systems-for-Home.shtml">Home Security Packages</a></li>'+
				'<li><a href="/residential/home-security-system-keypads.shtml">Keypads & Controls</a></li>'+
				'<li><a href="/residential/intrusion-alarms.shtml">Intrusion Alarms</a></li>'+
				'<li><a href="/residential/wireless-smoke-detectors.shtml">Wireless Smoke Detectors</a></li>'+
				'<li><a href="/residential/wireless-security-system.shtml">Wireless Security Systems</a></li>'+
				'<li><a href="/home-security-systems-and-alarm-monitoring.shtml">Home Security Systems & Remote Access Alarm Monitoring</a></li>'+

				'<li><a href="https://www.protection1.com/residential/identity-theft-protection.aspx">Identity Protection</a></li>'+
			'</ul>'+
		'</li>'+				
		'<li><a href="/residential/Home-Safety-and-Alarm-Systems-FAQ.shtml">Home Safety and Alarm System FAQ</a></li>'+	
		'<li><a href="/residential/Alarm-Systems-for-the-Home.shtml">Current Residential Customers</a>'+
		    '<ul id="res_currentcustGroup">'+
				'<li><a href="https://www.protection1.com/residential/transfer_service.aspx">$150 Credit for Movers</a></li>'+
				'<li><a href="https://www.protection1.com/residential/request_maintenance.aspx">Request System Maintenance</a></li>'+
				'<li><a href="https://www.protection1.com/global/update_emergency_contacts.aspx">Update Emergency Contacts</a></li>'+
				'<li><a href="https://www.protection1.com/global/refer_friend.aspx">Refer a Friend</a></li>'+
				'<li><a href="https://www.protection1.com/residential/upgrade_system.aspx">Upgrade Your System</a></li>'+
				'<li><a href="https://www.protection1.com/global/order_decals.aspx">Order Decals & Yard Signs</a></li>'+
				'<li><a href="/residential/safety_tips.shtml">Safety Tips</a></li>'+
				'<li><a href="/neighborhood_watch/index.shtml">Neighborhood Watch Program</a></li>'+
				'<li><a href="/global/prevent_false_alarms.shtml">Prevent False Alarms</a></li>'+
			'</ul>'+
        '</li>'+
		'<li><a href="/lp/CO/index.aspx">New CO Detector Laws</a>'+
        '</li>'+
    '</ul>'+
    '<ul class="bus">'+
		'<li><a href="/business/business-security-camera-systems.shtml">The Protection 1 Advantage</a>'+
        '</li>'+
		'<li><a href="/business/security-cameras-for-business.shtml">Small & Medium Business</a>'+
		    '<ul id="bus_smbGroup">'+
                '<li><a href="/business/sm_multi-site_solutions.shtml">Multi-Site Solutions</a></li>'+
                '<li><a href="/business/security_tips.shtml">Security Tips</a></li>'+
			'</ul>'+
        '</li>'+
        '<li><a href="/business/commercial-security-systems.shtml">National Accounts</a>'+
		    '<ul id="bus_nlbGroup">'+
                '<li><a href="/business/nl_multi-site_solutions.shtml">Multi-Site Solutions</a></li>'+
                '<li><a href="/business/project_delivery.shtml">Project Delivery</a></li>'+
                '<li><a href="/business/purchasing_advice.shtml">Purchasing Advice</a></li>'+
			'</ul>'+
        '</li>'+
		
		 '<li><a href="http://www.nmfc.com/" target="_blank">Multifamily</a>'+
		 '</li>'+
		
        '<li><a href="/business/commercial-security-service.shtml">Commercial Security Service</a>'+
		    '<ul id="bus_productsGroup">'+
                '<li><a href="/business/intrusion-detection-system.shtml">Intrusion Detection System</a></li>'+
                '<li><a href="/business/fire-safety-alarm-systems.shtml">Fire Safety Alarm Systems</a></li>'+
                '<li><a href="/business/security-system-access-control.shtml">Security System Access Control</a></li>'+
                '<li><a href="/business/surveillance-cameras.shtml">Surveillance Cameras (CCTV)</a></li>'+
                '<li><a href="/business/remote-video-surveillance-systems.shtml">Remote Video Surveillance Systems</a></li>'+
				'<li><a href="/business/asset-protection.shtml">Asset Protection Sensor</a></li>'+
				'<li><a href="/business/corporate-security-systems.shtml">Online Account Management</a></li> '+ 	
			'</ul>'+
        '</li>'+
		//'<li><a href="/business/e-secure.shtml#">eSecure</a></li>'+
		'<li><a href="https://www.protection1.com/business/site_risk.aspx">FREE Security Evaluation</a></li>'+

	'</ul>'+
	'<ul class="global">'+
	    '<li><strong>Press Room</strong>'+
	    '<ul id="pressRoom">'+
	        '<li><a href="/global/press_releases.shtml">Press Releases</a></li>'+
			'<li><a href="/global/in_the_news.shtml">In The News</a></li>'+
	        /*'<li><a href="/global/protection_one_foundation.shtml">Protection 1 Foundation</a></li>'+*/
	        /*'<li><a href="/global/press_kit.shtml">Press Kit</a></li>'+*/
	    '</ul>'+
	    '</li>'+
    '</ul>';                 

    
    flashPromoGlobal = '<div id="flashPromoAlt">'+
        '<div><a href="http://www.protection1.com/residential/protection_one_advantage.shtml"><img src="/_images/callouts/call_out_r.jpg" width="224" height="90" alt="Providing trustworthy home and business protection with state-of-the-art security technology and custom security plans" /></a></div>'+
        '<div><a href="http://www.protection1.com/residential/security_tips.shtml"><img src="/_images/callouts/call_out_m.jpg" width="224" height="90" alt="Protect Your Loved Ones" /></a></div>'+
        '<div><a href="http://www.protection1.com/home-security-systems-and-alarm-monitoring.shtml"><img src="/_images/callouts/call_out_b.jpg" width="224" height="90" alt="Be Secure with e-Secure" /></a></div>'+
        '<div><a href="https://www.protection1.com/global/refer_friend.aspx"><img src="/_images/callouts/call_out_i.jpg" width="224" height="90" alt="Refer a Friend" /></a></div>'+
    '</div>';
    
    flashPromoRes = ''+
    '<div id="flashPromoAlt">'+
         '<div><a href="http://www.protection1.com/residential/security_tips.shtml"><img src="/_images/callouts/call_out_m.jpg" width="224" height="90" alt="Protect Your Loved Ones" /></a></div>'+
         '<div><a href="http://www.protection1.com/home-security-systems-and-alarm-monitoring.shtml"><img src="/_images/callouts/call_out_b.jpg" width="224" height="90" alt="Be Secure with e-Secure" /></a></div>'+
         '<div><a href="https://www.protection1.com/residential/transfer_service.aspx"><img src="/_images/callouts/call_out_d.jpg" width="224" height="90" alt="Get $150 toward a new security system when you move. Don\'t live without security from Protection 1" /></a></div>'+
         '<div><a href="https://www.protection1.com/residential/activate_system.aspx"><img src="/_images/callouts/call_out_p.jpg" width="224" height="90" alt="Switch to Protection 1 for superior customized service and enjoy 2 months free!" /></a></div>'+
    '</div>';
    
    flashPromoBus = ''+
    '<div id="flashPromoAlt">'+
        '<div><a href="http://www.protection1.com/residential/protection_one_advantage.shtml"><img src="/_images/callouts/call_out_r.jpg" width="224" height="90" alt="Providing trustworthy home and business protection with state-of-the-art security technology and custom security plans" /></a></div>'+
        '<div><a href="https://www.protection1.com/residential/request_evaluation.aspx"><img src="/_images/callouts/call_out_q.jpg" width="224" height="90" alt="Satisfied Customers" /></a></div>'+
        '<div><a href="http://www.protection1.com/residential/protection_one_advantage.shtml"><img src="/_images/callouts/call_out_h.jpg" width="224" height="90" alt="Know You\'re Covered" /></a></div>'+
        '<div><a href="http://www.protection1.com/global/local_branches.shtml"><img src="/_images/callouts/call_out_g.jpg" width="224" height="90" alt="On-Staff Security" /></a></div>'+
    '</div>';
    
    $('#header').prepend(headertxt);
    $('#nav0').prepend(nav0txt);
    $('#nav1').prepend(nav1txt);
    
    //Write Flash Promo piece based on section (global, business, residential)
    $('#flashCalloutG').prepend(flashPromoGlobal);
    $('#flashCalloutR').prepend(flashPromoRes);
    $('#flashCalloutB').prepend(flashPromoBus);
    
    $(function(){
       var path = location.pathname.substring(1);
       if ( path )
         $('#nav1 a[@href$="' + path + '"]').attr('class', 'selected');
     });

});

// $ != jQuery from here on
jQuery.fn.extend({
	
	
    
	// hook up faqs for expanding and collapsing
	make_faqs: function() {
	
		return this
			.each(function() {
				jQuery('#'+this.id+'Controls')
					.find('.expand, .collapse')
						.bind('click', function(event) {
							this.blur();
							var id = jQuery(this).parents('.faqControls').attr('id').replace(/(Controls)$/, '');
							jQuery('dt, dd', '#'+id)[ jQuery(this).is('.expand') ? 'addClass' : 'removeClass' ]('opened');
							return false;
						});
			})
			.find('dt')
				.wrapInner('<a href="#" />')
				.find('a')
					.bind('click', function(event) {
						jQuery(this)
							.blur()
							.parent()
								.toggleClass('opened')
							.next()
								.toggleClass('opened');
						return false;
					})
				.end()
			.end();
	}
});


// Services Drop Down 
function jumpJumpMenu(){
    location=document.Jump.menu.options[document.Jump.menu.selectedIndex].value;
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=820,height=620,left = 112,top = 84');");
}

function changeVar(linkvar) {
link = linkvar;
}

    // var $nav1 = $('div#nav1');
    // var $prim = $('div#primary');
    // var $sec = $('div#secondary');
    // 
    // var heightArr = [$nav1.height(),$prim.height(),$sec.height()];
    //     var largest = 0;
    //     for(i=0; i<heightArr.length; i++){
    //         alert(heightArr[i]);
    //         if(heightArr[i] > largest){
    //             largest = heightArr[i];
    //         }
    //     }
    //     $nav1.height(parseInt(largest)+20);
    //     $prim.height(parseInt(largest)+20);
    //     $sec.height(parseInt(largest)+20);

