
	/* Make Rocket Go Now */
	$(function() {

		$('body').addClass('js');

		$('.other_cables a').click(function() {
			$(this).attr('target', '_blank')
		})

		$('tr:nth-child(even)').addClass('even')
		$('th:last-child').addClass('last')
		$('td:last-child').addClass('last')

		$('td.del a').deleteCableRow()
		$('.back_warn').infoPanel()
		$('.quote_animation').prepAnimation()
		$('.sample_table a').samplePicker()
		$('.swf').prepFlash()

	});



	/* PLUGINS */

	//	Sort out sidebar animation
	;(function($) {
		$.fn.prepAnimation = function() {

			var e  = $(this)
			var a  = $('a', e)
			var ul = $('ul', e)
			var li = ul.children()

			li.click(function() {
				window.location = a.attr('href')
			})

			ul.cycle({
				timeout: 5000
			})

			return this;

		}
	})(jQuery);



	//	Prep flash
	;(function($) {
		$.fn.prepFlash = function() {
			return this.each(function() {

				var swf_div  = $(this);
				var swf_file = swf_div.attr('id')

				swf_div.flash({
					swf: '/incs/flash/' + swf_file + '.swf',
					params: {
						allowfullscreen: true,
						allowscriptaccess: 'always'
					},
					height: 224,
					width: 470
				})

			})
		}
	})(jQuery);



	//	Delete Cable Rows
	;(function($) {
		$.fn.deleteCableRow = function() {
			return this.click(function() {

				var a        = $(this);
				var form     = a.closest('form')
				var fieldset = a.closest('fieldset')
				var this_row = a.closest('tr')
				var row_cols = $('td', this_row)

				$.ajax({
					url: a.attr('href'),
					data: { ajax: true },
					success: function() {
						row_cols.css('background', '#fcc')

						this_row.fadeOut('slow', function() {
							this_row.remove()

							if ($('tbody tr', fieldset).length == 0) {
								fieldset.fadeOut('slow', function() {
									fieldset.remove()

									if ($('fieldset', form).length == 1) {
										window.location = '/quote/request-cancelled/';
									}
								})
							}
						})
					}
				})

				return false;
			})
		}
	})(jQuery);



	//	Cable picker adder/remover
	;(function($) {
		$.fn.samplePicker = function() {
			return this.click(function() {

				var a = $(this)

				$.ajax({
					url: a.attr('href'),
					data: { ajax: true },
					success: function() {
						if (a.hasClass('chosen')) {
							link_text = 'Remove';
							a.removeClass('chosen')
						}
						else {
							link_text = 'Add';
							a.addClass('chosen hover')

							a.one('mouseout', function() {
								$(this).removeClass('hover')
							})
						}

						a.text(link_text)
					}
				})

				return false;
			})
		}
	})(jQuery);



	//	InfoPanel
	;(function($) {
		$.fn.infoPanel = function () {
			return this.click(function() {

				var back_link   = $(this)
				var destination = back_link.attr('href')

				if ($('.infopanel')[0]) return false;

				$.get(
					'/incs/actions/infopanel.php?destination=' + destination,
					function(response) {
						$(response).insertAfter(back_link)

						var infopanel = $('.infopanel')

						$('.infopanel_cancel').click(function() {
							infopanel.remove()
							return false;
						})
					}
				)

				return false;

			})
		}
	})(jQuery);



	//	--

	//	Log
	;(function($){$.fn.log=function(message){console.log("%s: %o",message,this);return this}})(jQuery);

	//	SWFObject
	;(function(E,B){var C=function(G){var F,H=[];for(F in G){H.push(F+'="'+G[F]+'"')}return H.join("")},D=function(H){var F,J,I=[],G;for(F in H){if(typeof H[F]=="object"){G=[];for(J in H[F]){G.push([J,"=",encodeURIComponent(H[F][J])].join(""))}H[F]=G.join("&amp;")}I.push(['<param name="',F,'" value="',H[F],'" />'].join(""))}return I.join("")},A=false;E[B]=(function(){var F="0,0,0",G=navigator.plugins["Shockwave Flash"]||ActiveXObject;F=G.description||(function(){try{return(new G("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}catch(H){}}());F=F.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+r|,)(\d+)/);return{available:F[1]>0,activeX:!G.name,version:{major:F[1]*1,minor:F[2]*1,release:F[3]*1},hasVersion:function(I){var L=this.version,J="major",K="minor",H="release";I=(/string|number/.test(typeof I))?I.toString().split("."):I||[0,0,0];I=[I[J]||I[0]||L[J],I[K]||I[1]||L[K],I[H]||I[2]||L[H]];return(I[0]<L[J])||(I[0]==L[J]&&I[1]<L[K])||(I[0]==L[J]&&I[1]==L[K]&&I[2]<=L[H])},expressInstall:"expressInstall.swf",create:function(H){if(!E[B].available||A||!typeof H=="object"||!H.swf){return false}if(H.hasVersion&&!E[B].hasVersion(H.hasVersion)){H={swf:H.expressInstall||E[B].expressInstall,attrs:{id:"SWFObjectExprInst",height:Math.max(H.height||137),width:Math.max(H.width||214)},params:{flashvars:{MMredirectURL:location.href,MMplayerType:(E[B].activeX)?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}};A=true}else{H=E.extend(true,{attrs:{height:H.height||180,width:H.width||320},params:{wmode:H.wmode||"opaque",flashvars:H.flashvars}},H)}return"<object "+(C(H.attrs))+(E[B].activeX?' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="'+H.swf+'" />':' type="application/x-shockwave-flash" data="'+H.swf+'">')+(D(H.params))+"</object>"}}}());E.fn[B]=function(F){if(typeof F=="object"){this.each(function(){var G=document.createElement(B);G.innerHTML=E[B].create(F);if(G.childNodes[0]){this.appendChild(G.childNodes[0])}})}else{if(typeof F=="function"){this.find("object").andSelf().filter("object").each(function(){var H=this,G="jsInteractionTimeoutMs";H[G]=H[G]||0;if(H[G]<660){if(H.clientWidth||H.clientHeight){F.call(this)}else{setTimeout(function(){E(H)[B](F)},H[G]+66)}}})}}return this}}(jQuery,"flash"));

	//	Cycle Lite
	;(function(D){var A="Lite-1.0";D.fn.cycle=function(E){return this.each(function(){E=E||{};if(this.cycleTimeout){clearTimeout(this.cycleTimeout)}this.cycleTimeout=0;this.cyclePause=0;var I=D(this);var J=E.slideExpr?D(E.slideExpr,this):I.children();var G=J.get();if(G.length<2){if(window.console&&window.console.log){window.console.log("terminating; too few slides: "+G.length)}return }var H=D.extend({},D.fn.cycle.defaults,E||{},D.metadata?I.metadata():D.meta?I.data():{});H.before=H.before?[H.before]:[];H.after=H.after?[H.after]:[];H.after.unshift(function(){H.busy=0});var F=this.className;H.width=parseInt((F.match(/w:(\d+)/)||[])[1])||H.width;H.height=parseInt((F.match(/h:(\d+)/)||[])[1])||H.height;H.timeout=parseInt((F.match(/t:(\d+)/)||[])[1])||H.timeout;if(I.css("position")=="static"){I.css("position","relative")}if(H.width){I.width(H.width)}if(H.height&&H.height!="auto"){I.height(H.height)}var K=0;J.css({position:"absolute",top:0,left:0}).hide().each(function(M){D(this).css("z-index",G.length-M)});D(G[K]).css("opacity",1).show();if(D.browser.msie){G[K].style.removeAttribute("filter")}if(H.fit&&H.width){J.width(H.width)}if(H.fit&&H.height&&H.height!="auto"){J.height(H.height)}if(H.pause){I.hover(function(){this.cyclePause=1},function(){this.cyclePause=0})}D.fn.cycle.transitions.fade(I,J,H);J.each(function(){var M=D(this);this.cycleH=(H.fit&&H.height)?H.height:M.height();this.cycleW=(H.fit&&H.width)?H.width:M.width()});J.not(":eq("+K+")").css({opacity:0});if(H.cssFirst){D(J[K]).css(H.cssFirst)}if(H.timeout){if(H.speed.constructor==String){H.speed={slow:600,fast:200}[H.speed]||400}if(!H.sync){H.speed=H.speed/2}while((H.timeout-H.speed)<250){H.timeout+=H.speed}}H.speedIn=H.speed;H.speedOut=H.speed;H.slideCount=G.length;H.currSlide=K;H.nextSlide=1;var L=J[K];if(H.before.length){H.before[0].apply(L,[L,L,H,true])}if(H.after.length>1){H.after[1].apply(L,[L,L,H,true])}if(H.click&&!H.next){H.next=H.click}if(H.next){D(H.next).bind("click",function(){return C(G,H,H.rev?-1:1)})}if(H.prev){D(H.prev).bind("click",function(){return C(G,H,H.rev?1:-1)})}if(H.timeout){this.cycleTimeout=setTimeout(function(){B(G,H,0,!H.rev)},H.timeout+(H.delay||0))}})};function B(J,E,I,K){if(E.busy){return }var H=J[0].parentNode,M=J[E.currSlide],L=J[E.nextSlide];if(H.cycleTimeout===0&&!I){return }if(I||!H.cyclePause){if(E.before.length){D.each(E.before,function(N,O){O.apply(L,[M,L,E,K])})}var F=function(){if(D.browser.msie){this.style.removeAttribute("filter")}D.each(E.after,function(N,O){O.apply(L,[M,L,E,K])})};if(E.nextSlide!=E.currSlide){E.busy=1;D.fn.cycle.custom(M,L,E,F)}var G=(E.nextSlide+1)==J.length;E.nextSlide=G?0:E.nextSlide+1;E.currSlide=G?J.length-1:E.nextSlide-1}if(E.timeout){H.cycleTimeout=setTimeout(function(){B(J,E,0,!E.rev)},E.timeout)}}function C(E,F,I){var H=E[0].parentNode,G=H.cycleTimeout;if(G){clearTimeout(G);H.cycleTimeout=0}F.nextSlide=F.currSlide+I;if(F.nextSlide<0){F.nextSlide=E.length-1}else{if(F.nextSlide>=E.length){F.nextSlide=0}}B(E,F,1,I>=0);return false}D.fn.cycle.custom=function(K,H,I,E){var J=D(K),G=D(H);G.css({opacity:0});var F=function(){G.animate({opacity:1},I.speedIn,I.easeIn,E)};J.animate({opacity:0},I.speedOut,I.easeOut,function(){J.css({display:"none"});if(!I.sync){F()}});if(I.sync){F()}};D.fn.cycle.transitions={fade:function(F,G,E){G.not(":eq(0)").css("opacity",0);E.before.push(function(){D(this).show()})}};D.fn.cycle.ver=function(){return A};D.fn.cycle.defaults={timeout:4000,speed:1000,next:null,prev:null,before:null,after:null,height:"auto",sync:1,fit:0,pause:0,delay:0,slideExpr:null}})(jQuery)
