// 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.ProtectionOne.com/index.shtml" title="Protection One: Your home and business security provider with customized security solutions">Protection One &ndash; Home and Business Security</a></span><span style="position: absolute; top: 30px; left: 200px; z-index: 1000; margin: 0; padding: 0; width: 185px; height: 77px;"><a href="https://www.protectionone.com/residential/request_evaluation.aspx"><img src="/_images/header_banner.gif" border="0"></a></span>'+
		'<ul id="links" style="top: 15px">'+
			'<li><a onclick="window.open(\'http://www.protectionone.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.protectionone.com/residential/existing_systems.shtml">Current Customers</a></li>'+
			'<li><a href="http://www.ProtectionOne.com/global/customer_service.shtml">Customer Service</a></li>'+
			'<li><a href="http://www.ProtectionOne.com/global/local_branches.shtml">Branch Locator</a></li>'+
			//'<li><a href="http://www.ProtectionOne.com/residential/email_signup.shtml">Email Sign-up</a></li>'
			'<li class="last"><a href="http://www.protectionone.com/global/terms_of_use.shtml">Terms of Use</a></li>'+
		'</ul>'+
		'<ul id="helpLinks" style="top: 36px">' +
			'<li class="num"></li>'+
			'<li class="chat"></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 One 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</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 &mdash; Brivo</option>'+
			'<option value="https://www.protectionone.com/secureaccess">Secure Access &mdash; 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="/residential/index.shtml" id="resLink">Residential</a></li>'+
			'<li><a href="/business/index.shtml" id="busLink">Business</a></li>'+
		'</ul>';
    
    nav1txt = ''+
	'<ul class="res">'+
		'<li><a href="/residential/products_services.shtml">Home Security Products</a>'+
			'<ul id="res_productsGroup">'+
				'<li><a href="/residential/home_security_packages.shtml">&ndash; Home Security Packages</a></li>'+
				'<li><a href="/residential/keypads_controls.shtml">&ndash; Keypads &amp; Controls</a></li>'+
				'<li><a href="/residential/intrusion_detectors.shtml">&ndash; Intrusion Detectors</a></li>'+
				'<li><a href="/residential/hazard_detectors.shtml">&ndash; Hazard Detectors</a></li>'+
				'<li><a href="/residential/cellular_backup.shtml">&ndash; Cellular Backup</a></li>'+
				'<li><a href="/residential/remote_services.shtml">&ndash; eSecure</a></li>'+
				'<li><a href="/residential/asset-protection-sensor.shtml">&ndash; Asset Protection Sensor</a></li>'+
			'</ul>'+
		'</li>'+
		'<li><a href="http://www.ProtectionOne.com/residential/24-hour_monitoring.shtml">24-Hour Monitoring</a>'+
		    '<ul id="res_monitoringGroup">'+
				'<li><a href="http://www.ProtectionOne.com/residential/how_monitoring_works.shtml">&ndash; How Monitoring Works</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/residential/speedy_response.shtml">&ndash; Speedy Response</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/residential/24-7_monitoring.shtml">&ndash; 24/7 Monitoring</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/residential/home_hazards.shtml">&ndash; Home Hazards</a></li>'+
			'</ul>'+
        '</li>'+				
		'<li><a href="http://www.ProtectionOne.com/residential/protection_one_advantage.shtml">Protection One Advantage</a>'+
		    '<ul id="res_advantageGroup">'+
				'<li><a href="http://www.ProtectionOne.com/residential/local_branches.shtml">&ndash; Local Branches</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/residential/our_staff.shtml">&ndash; Our Trusted Expert Staff</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/residential/no_phone_line.shtml">&ndash; No Phone Line?</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/residential/advanced_technology.shtml">&ndash; Advanced Technology</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/residential/our_customers.shtml">&ndash; Our Customers Speak</a></li>'+
				'<li><a href="/residential/video_testimonials.shtml">&ndash; Video Testimonials</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/residential/online_account.shtml">&ndash; Online Account Management</a></li>'+
			'</ul>'+
        '</li>'+
		'<li><a href="http://www.ProtectionOne.com/residential/security_analysis.shtml">Security Analysis</a>'+
		    '<ul id="res_analysisGroup">'+
				//'<li><a onclick="window.open(\'https://www.protectionone.com/pop-advisor.shtml\',\'chat\',\'height=600,width=850,scrollbars=yes\');" href="javascript:void(0)">&ndash; Security Wizard</a></li>'+
				'<li><a href="https://www.protectionone.com/residential/request_evaluation.aspx">&ndash; Request Evaluation</a></li>'+
				//'<li><a href="http://www.ProtectionOne.com/residential/safety_tips.shtml">&ndash; Safety Tips</a></li>'+
				//'<li><a href="http://www.protectionone.com/pets/">&ndash; Pet Decals</a></li>'+
				//'<li><a href="http://www.protectionone.com/pet_safety/">&ndash; Pet Safety</a></li>'+
			'</ul>'+
        '</li>'+
		'<li><a href="http://www.ProtectionOne.com/residential/home_security_qa.shtml">Home Security Q&amp;A</a></li>'+		    
		'<li><a href="http://www.ProtectionOne.com/residential/existing_systems.shtml">Current Customers</a>'+
		    '<ul id="res_currentcustGroup">'+
				'<li>&ndash; <a href="https://www.protectionone.com/residential/transfer_service.aspx">Moving? Take Your Service With You</a></li>'+
				'<li>&ndash; <a href="https://www.protectionone.com/residential/request_maintenance.aspx">Request System Maintenance</a></li>'+
				'<li>&ndash; <a href="https://www.protectionone.com/global/update_emergency_contacts.aspx">Update Emergency Contacts</a></li>'+
				'<li>&ndash; <a href="https://www.protectionone.com/global/refer_friend.aspx">Refer a Friend</a></li>'+
				'<li>&ndash; <a href="https://www.protectionone.com/residential/upgrade_system.aspx">Upgrade Your System</a></li>'+
				'<li>&ndash; <a href="https://www.protectionone.com/global/order_decals.aspx">Order Window Decals or Yard Signs</a></li>'+
				'<li>&ndash; <a href="/residential/safety_tips.shtml">Safety Tips</a></li>'+
				'<li>&ndash; <a href="/pet_safety/">Pet Safety Tips</a></li>'+
				'<li>&ndash; <a href="/neighborhood-watch">Neighborhood Watch Program</a></li>'+
				'<li>&ndash; <a href="/global/prevent_false_alarms.shtml">Prevent False Alarms</a></li>'+
				'<li>&ndash; <a href="/global/existing_analog_system.shtml">FCC Analog Shutdown</a></li>'+		
			'</ul>'+
        '</li>'+
    '</ul>'+
    '<ul class="bus">'+
		'<li><a href="http://www.ProtectionOne.com/business/sm_business.shtml">Small &amp; Medium Business</a>'+
		    '<ul id="bus_smbGroup">'+
                '<li><a href="http://www.ProtectionOne.com/business/sm_multi-site_solutions.shtml">&ndash; Multi-Site Solutions</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/security_tips.shtml">&ndash; Security Tips</a></li>'+
			'</ul>'+
        '</li>'+
        '<li><a href="http://www.ProtectionOne.com/business/nl_business.shtml">National &amp; Large Business</a>'+
		    '<ul id="bus_nlbGroup">'+
                '<li><a href="http://www.ProtectionOne.com/business/nl_multi-site_solutions.shtml">&ndash; Multi-Site Solutions</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/project_delivery.shtml">&ndash; Project Delivery</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/purchasing_advice.shtml">&ndash; Purchasing Advice</a></li>'+
			'</ul>'+
        '</li>'+
        '<li><a href="/business/products_services.shtml">Products &amp; Services</a>'+
		    '<ul id="bus_productsGroup">'+
                '<li><a href="/business/intrusion_detectors.shtml">&ndash; Intrusion Detectors</a></li>'+
                '<li><a href="/business/fire_hazard_detectors.shtml">&ndash; Fire &amp; Hazard Detectors</a></li>'+
                '<li><a href="/business/access_control.shtml">&ndash; Access Control</a></li>'+
                '<li><a href="/business/video_surveillance.shtml">&ndash; Video Surveillance (CCTV)</a></li>'+
                '<li><a href="/business/remote_services.shtml">&ndash; Remote Services</a></li>'+
				'<li><a href="/business/asset-protection-sensor.shtml">&ndash; Asset Protection Sensor</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/business/online_account.shtml">&ndash; Online Account Management</a></li> '+ 	
			'</ul>'+
        '</li>'+
		'<li><a href="/business/e-secure.shtml#">eSecure</a></li>'+
        '<li><a href="http://www.ProtectionOne.com/business/24-7_monitoring.shtml">24/7 Monitoring</a>'+
		    '<ul id="bus_monitoringGroup">'+
                '<li><a href="http://www.ProtectionOne.com/business/speedy_response.shtml">&ndash; Speedy Response</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/monitoring_center.shtml">&ndash; Monitoring Center</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/hazard_detection.shtml">&ndash; Hazard Detection</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/triple_redundancy.shtml">&ndash; Triple Redundancy</a></li>'+
			'</ul>'+
        '</li>'+
        '<li><a href="http://www.ProtectionOne.com/business/protection_one_advantage.shtml">Protection One Advantage</a>'+
		    '<ul id="bus_advantageGroup">'+
                '<li><a href="http://www.ProtectionOne.com/business/local_branches.shtml">&ndash; Local Branches</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/dedicated_security.shtml">&ndash; Dedicated to Security</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/advanced_technology.shtml">&ndash; Advanced Technology</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/our_staff.shtml">&ndash; Our Trusted Expert Staff</a></li>'+
                '<li><a href="http://www.ProtectionOne.com/business/financial_focus.shtml">&ndash; Financial Focus</a></li>'+
				'<li><a href="http://www.ProtectionOne.com/business/our_customers.shtml">&ndash; Our Customers Speak</a></li>'+
				'<li><a href="/business/video_testimonials.shtml">&ndash; Video Testimonials</a></li>'+                          
			'</ul>'+
        '</li>'+
        '<li><a href="http://www.protectionone.com/business/casestudies.shtml">Case Studies</a></li>'+
		'<li><a href="https://www.protectionone.com/business/site_risk.aspx">Site Risk Assessment</a></li>'+
		'<li><a href="/business/memorandum-of-insurance.shtml">Memorandum of Insurance (MOI)</a></li>'+
		'<BR><BR><li><a href="http://shapeofsecurity.com/home.aspx">Industry Specialization</a>'+
		    '<ul style="display: inline">'+
                '<li><a href="http://shapeofsecurity.com/home.aspx">&ndash; Logistics</a></li>'+
                '<li><a href="http://shapeofsecurity.com/home.aspx">&ndash; Manufacturing/Warehouse</a></li>'+
                '<li><a href="http://shapeofsecurity.com/home.aspx">&ndash; Restaurant</a></li>'+                         
			'</ul>'+
        '</li>'+
        '<li>'+		    
		    '<h3>Get Protection Now</h3>'+
	        '<ul class="getProtect">'+
		        '<li><a href="https://www.protectionone.com/business/new_installations.aspx">New Installations</a></li>'+
		        '<li><a href="http://www.ProtectionOne.com/business/existing_systems.shtml">Existing Systems</a></li>'+	
	        '</ul>'+	
        '</li>'+
	'</ul>'+
	'<ul class="global">'+
	    '<li><strong>Press Room</strong>'+
	    '<ul id="pressRoom">'+
	        '<li><a href="http://www.protectionone.com/global/in_the_news.shtml">&ndash; In The News</a></li>'+
	        '<li><a href="http://www.protectionone.com/global/press_releases.shtml">&ndash; Press Releases</a></li>'+
	        /*'<li><a href="/global/protection_one_foundation.shtml">&ndash; Protection One Foundation</a></li>'+*/
	        /*'<li><a href="/global/press_kit.shtml">&ndash; Press Kit</a></li>'+*/
	    '</ul>'+
	    '</li>'+
    '</ul>';                 

    
    flashPromoGlobal = '<div id="flashPromoAlt">'+
        '<div><a href="http://www.ProtectionOne.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.ProtectionOne.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.ProtectionOne.com/residential/remote_services.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.protectionone.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.ProtectionOne.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.ProtectionOne.com/residential/remote_services.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.protectionone.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 One" /></a></div>'+
         '<div><a href="https://www.protectionone.com/residential/activate_system.aspx"><img src="/_images/callouts/call_out_p.jpg" width="224" height="90" alt="Switch to Protection One for superior customized service and enjoy 2 months free!" /></a></div>'+
    '</div>';
    
    flashPromoBus = ''+
    '<div id="flashPromoAlt">'+
        '<div><a href="http://www.ProtectionOne.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.protectionone.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.ProtectionOne.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.ProtectionOne.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);
