var glbdbg;

var utils = {
	/*********************************
	 * PUBLIC METHODS                *
	 *********************************/

	// Method to set up Accordion
	initAccordion : function(name, content_selector, toggler_selector, argShow, argAlwaysHide, myFunction) {
		argShow = (argShow != null) ? Number(argShow) : -1;
		argAlwaysHide = argAlwaysHide || false;
		myFunction = myFunction || function() {};

		// Create accordion object if it doesn't exist
		if (typeof(accordions) == 'undefined') {
			accordions = new Array();
		}
        
      
        
		accordions[name] = new Fx.Accordion($$(toggler_selector),
											$$(content_selector), {
												show:			argShow,
												alwaysHide:		argAlwaysHide,
												transition:		Fx.Transitions.quadOut,
												opacity:		false,
												wait:			false,
												onComplete:		eval(myFunction)
											});
											
	     //Define the togglers of the accordion
	    accordions[name].togglers = $$(toggler_selector);
	    this.setTogglerEvents(name,accordions[name].togglers);
	  
	},
	
	// onComplete method for Accordion styles
	setTogglerEvents : function(name, toggler) {
		
		if (name) {
			// adding link tracking to the Accordians
			 accordions[name].togglers.each(function(item) {
				item.addEvent('click', function() {
					var cur_lid = "";
					cur_lid += this.firstChild.innerHTML;
					linkTrack("content", cur_lid);
				});
			});
		}
			
		var curItem = "";

		if (name == 'ip') {
			 accordions[name].togglers.each(function(item) {
			    item.getFirst().addClass('togglerOff');
			    item.addClass('togglerIpOff');
				item.addEvent('click', function() {
					if (curItem != '') {
						curItem.getLast().setStyle('visibility','visible');
						curItem.removeClass('togglerIpOn');
						curItem.getFirst().removeClass('togglerOn');
						curItem.addClass('togglerIpOff');
						curItem.getFirst().addClass('togglerOff');
					}
					curItem = this;
					curItem.getLast().setStyle('visibility','hidden');
					curItem.removeClass('togglerIpOff');
					curItem.getFirst().removeClass('togglerOff');
					curItem.addClass('togglerIpOn');
					curItem.getFirst().addClass('togglerOn');
					// for self clicking
					var parent_item = item.getParent();
					var parent_item_id = parent_item.getProperty('id');
					var p_plan_height = $('p_plan').getCoordinates().height;
					var m_plan_height = $('m_plan').getCoordinates().height;
					if($(parent_item_id).getCoordinates().height > 200){
						item.getLast().setStyle('visibility','visible');
						item.removeClass('togglerIpOn');
						item.getFirst().removeClass('togglerOn');
						item.addClass('togglerIpOff');
						item.getFirst().addClass('togglerOff');
					}
					/*
					if(parent_item_id == "m_plan"){
						accordions['ip'].display(1);
					}else{
						accordions['ip'].display(0);
					}
					*/
				});
			});
		}
	},

	// Method to set up Tool Tips
	makeTips : function(browserOffset, eleClass, tipClassName) {
		if (window.ie || navigator.appVersion.indexOf("Mac") != -1) {
			var HeaderTips = new Tips($$(eleClass), {
										className: tipClassName,
										offsets: browserOffset
									});
		}
		else {
			var HeaderTips = new Tips($$(eleClass), {
				className: tipClassName,
				offsets: browserOffset,
				initialize: function() {
					this.fx = new Fx.Style(this.toolTip, 'opacity', {
											duration: 500,
											wait: false
										}).set(0);
				},
				onShow: function(toolTip) {this.fx.start(1);},
				onHide: function(toolTip) {this.fx.start(0);}
			});
		}
	},

	// Set Auto Tabbing for Phone Fields
	phoneTab : function(argInput) {
		if (argInput.name != 'phoneLineNumber') {
			if (argInput.value && argInput.value.length == argInput.getAttribute("maxlength")) {
				$(argInput).getNext('input').focus();
			}
		}
	},
	
	initHeaderRotator : function() {
		this.imageRotator('sc_header_nav_container', 3, '/shared/images/service_contracts/');
	},
	
	
	/*********************************
	 * PRIVATE  METHODS              *
	 *********************************/

	imageRotator : function (target, total, path) {
		target = $(target);
		if (target) {
			target.setStyle('background', "transparent url('" + path + "header_" + (Math.floor(Math.random() * total)).toString() + ".jpg') no-repeat right top");
		}
	}
}
