// JavaScript Document

document.write('<link href="/smallworld/media/css/javascript.css" rel="stylesheet" type="text/css" media="all" />');
Cufon.set('fontFamily', 'VAG Rounded').replace('h1,h2:not(.nocufon),h3,h4,h5,h6, .h1, .header strong, .quote, .leftSection strong, .small_comment, div.btn div.br a, div.pbtn div.br, div.gbtn div.br, .prpl_line, .readMore, .footer,.panelFoot, div.pink div.br a, div.tab div.br a,ul.square li a, .bigi div, div.pbtn div.br div.bigText, table.bundles, .revealDiv, .bundlesectionNumber, .bundle_col_3 ul li, .map_cornercover, .cufon, .pb_text_right');

var $j = jQuery.noConflict();
var xhr;
var myInterval;
var headerInterval;
var galleryInterval;
var targetIndex;
var faderSections;
var gallerystep;
var marginStep;
var activeGallery;

$j(document).ready( function() {
	var locat = location.href;
	
	faderSections = $j('.imageFader:not(".homeFader")')
	faderSections = $j.grep(faderSections, function(a) { return $j(a).children('img, a').length > 1 });
	
	if($j(faderSections).length > 0) {
		$j(faderSections).each(function() {
			$j(this).children('img, a').hide().first().addClass('activeImg').show();
		});
		myInterval = setInterval("switchFaderImages()", 7000);
	}
	
	if($j('.homeFader').length > 0) {
		$j('.homeFader').each(function() {
			$j(this).children('img, a').hide().first().addClass('activeImg').show();
		});
		setTimeout("switchHomeFaderImages()", 5000);
	}
	
	$j(".mainmenu ul li a").each(function(){
		if(locat.indexOf(this.href) >= 0 || (locat == this.href.replace('Home.aspx',"")))
		{
			this.parentNode.className += " active"
		}
	});	
	$j(".submenu ul li a").each(function(){
		if(locat.indexOf(this.href) >= 0 || (locat == this.href.replace('Home.aspx',"")))
		{
			this.parentNode.className += " active"
		}
	});		
	
	$j('.header div.links').prepend('<span>Font size: <a href="javascript:changetoDefault()" class="a_s" title="Change the text to the default size.">A</a> | <a href="javascript:changetoMedium()" class="a_m" title="Change the text to a larger size.">A</a> | <a href="javascript:changetoLarge()" class="a_l" title="Change the text to the largest size.">A</a></span> &nbsp; ');
	
	$j(".revealDiv").click( function () {
		var mySection = $j(this).siblings('.revealedDiv');
		if($j(this).hasClass('activeReveal')) {
			$j(this).removeClass('activeReveal');
			mySection.stop(true,true).show().animate({ height: 'hide' }, 'slow');
		} else {
			$j(this).addClass('activeReveal');
			mySection.stop(true,true).hide().animate({ height: 'show' }, 'slow');
		}
	});
	$j(".revealedDiv").each( function() {
		if(!$j(this).hasClass('activeReveal')) {
			$j(this).hide();
		}
		$j(this).append('<div class="closeLink"></div>');
	});
	$j('.closeLink').click( function() {
		$j(this).parents(".revealedDiv").siblings('.revealDiv').click();
	});
	
	if($j('#officemap').length > 0) {
		$j('#officemap').parents('.map_body').hide().siblings('.map_head').click(function(){
			var dh = $j(this);
			if(dh.find('a').text() == "+") {
				dh.find('a').html("<span class='minuspad'>-</span>")
				dh.siblings('.map_body').show();
				if($j('#officemap').find('.gmnoprint').length == 0) {
					$j('#officemap').googleMap( {
						//zoom:9,
						poi: [ {
							latitude:54.05867,
							longitude:-2.840098,
							title:'Smallworld Morcambe',
							content:'<h4>Smallworld Morcambe</h4><p>Unit 9, Middlegate, <br />White Lund Industrial Estate, <br />Morecambe, Lancashire, LA3 3BN</p>',
							iconIndex:0
						},{
							latitude:55.59645,
							longitude:-4.636298,
							title:'Smallworld Irvine',
							content:'<h4>Smallworld Irvine</h4><p>3 Chalmers Place, <br />Riverside Business Park, Irvine, <br />Ayrshire, KA11 5DH</p>',
							iconIndex:0
						},{
							latitude:55.613905,
							longitude:-4.670082,
							title:'Smallworld Irvine Shop',
							content:'<h4>Irvine Shop</h4><p>Smallworld Cable, Unit 4, <br />The Forum Centre, <br />Irvine, KA12 8BA</p>',
							iconIndex:0
						}],
						icons: [
							{
								title:"Smallworld",
								'image':new google.maps.MarkerImage('/SMALLWORLD/media/interface/business/mapicon.png', new google.maps.Size(35, 41), new google.maps.Point(0,0), new google.maps.Point(16, 40)),
								'shadow':new google.maps.MarkerImage('/SMALLWORLD/media/interface/trans.gif', new google.maps.Size(35, 41), new google.maps.Point(0,0), new google.maps.Point(16, 40)),
								'over':new google.maps.MarkerImage('/SMALLWORLD/media/interface/business/mapicon_over.png', new google.maps.Size(35, 41), new google.maps.Point(0,0), new google.maps.Point(16, 40)),
								'out':new google.maps.MarkerImage('/SMALLWORLD/media/interface/business/mapicon.png', new google.maps.Size(35, 41), new google.maps.Point(0,0), new google.maps.Point(16, 40)),
								'shape':{ coord: [16,40,14,30,6,26,2,20,2,11,6,5,12,2,21,1,28,6,31,12,31,17,34,23,33,29,29,33,22,33,19,32], type: 'poly' }
							}
						],
						height:460,
						mapType:"ROADMAP",
						streetView:true,
						directions:true,
						directionsButton:'/SMALLWORLD/media/interface/business/btn_getdirections.gif'
					});
				}
			} else { 
				dh.siblings('.map_body').hide();
				dh.find('a').html("<span class='pluspad'>+</span>")
			}
		});
	}
	if($j('.imagegallery').length > 0) {
		$j('.imagegallery').imageGallery( { "nextPrevButtons":false, "transition":"fade", 'itemButtons':true });
	}
	$j('.drop_head').click(function() {
		var sibling = $j(this).siblings('.drop_body');
		if(sibling.css('display') == 'block') {
			sibling.stop(true,true).animate({height:'hide'},'slow');
			$j(this).find('input').attr('checked',false);
			$j(this).parent().removeClass("active");
		} else {
			sibling.stop(true,true).animate({height:'show'},'slow');
			$j(this).find('input').attr('checked',true);
			$j(this).parent().addClass("active");
		}
		if($j(this).attr('nodeName') == "A") {
			return false;
		}
	});
	
	$j('.drop_body').each( function() {
		if(!$j(this).parent().hasClass('active')) {
			$j(this).hide();
		}
	});
	$j(".tabs").tabs( {fx: { opacity: 'toggle' }, show:function() { Cufon.refresh(); } });
	Cufon.refresh('div.tab div.br a');
	$j('.newwindow').find('a').click(function() {
		window.open($j(this).attr('href'), 'NewWindow');
		return false;
	});
	$j('a.newwindow').click(function() {
		window.open($j(this).attr('href'), 'NewWindow');
		return false;
	});
	
	$j('.gallery').each(function() {
		$j(this).find('.gallery_contents').find('li').each( function(index) {
			$j(this).attr('index',index);
		});
	});
	activeGallery = $j('.gallery');
	activeGallery.prepend('<div class="left_button"><div></div></div>');
	activeGallery.prepend('<div class="right_button"><div></div></div>');
	$j('.left_button').click(moveOneLeft);
	$j('.right_button').click(moveOneRight);
	if($j('.gallery').length > 0) {
		myInterval = setInterval( "moveRight()", 7000);
	}
	
	
	$j('.gallery').each( function() {
		var egitem = $j(this).find('.gallery_contents').children('ul:first').children('li:first');
		var itemWidth = egitem.attr('offsetWidth');

		var pageWidth = $j(this).attr('offsetWidth');
		gallerystep = Math.floor(pageWidth/itemWidth);
		$j(this).attr('gallerystep', gallerystep);
		$j(this).attr('currentLeft', -itemWidth*gallerystep);
		
		var lis = $j(this).find('.gallery_contents').find('li');
		if(lis.length > gallerystep) {
			$j(this).find('.gallery_contents').css('margin-left',$j(this).attr('currentLeft')+"px");
			
			$j(this).find('.gallery_contents').find('li[index="0"]').addClass('active');
			for(var i=0;i<gallerystep;i++) {
				lis.parent().prepend($j(this).find('.gallery_contents').find('li:eq('+(lis.length-1)+')').detach());
			}
		}
	});
	
	$j('.movingHeader').children('.image').css('opacity','0').first().addClass("loadingImg");
	if($j('.movingHeader').length > 0) {
		getSlide();
	}
	iotbs();
	levelDivs();
	
	if($j('#TwitterFeed').length > 0) {
		$j.ajax({
			url: "http://api.twitter.com/1/statuses/user_timeline.json?count=2&include_rts=1&screen_name=smallworldcable&callback=?",
			dataType: 'jsonp',
			success: function(data) {
				var newHTML = '';
				for(var i=0;i<data.length;i++) {
					thisData = data[i];
					var thisText = thisData.text;
					var myArray = thisText.split('http://');
					var j = 0;
					if(thisText.indexOf('http://') > 0) {
						for(var j=1;j<myArray.length;j++) {
							var linkString = myArray[j].substring(0,myArray[j].indexOf(' '));
							myArray[j] = '<a href="http://'+linkString+'">' + myArray[j].replace(' ','</a> ');
						}
						thisText = myArray.join('');
					}
					var myDate = new Date();
					var tweetDate = new Date();
					tweetDate.setTime(getTimeFromTwStr(thisData.created_at));
					var differanceText = dateDifferance(myDate, tweetDate);
					newHTML += "<p><strong><a onclick=\"window.open(this.href);return false;\" onkeypress=\"window.open(this.href);return false;\" href='http://www.twitter.com/" + thisData.user.screen_name + "'>@" + thisData.user.screen_name +"</a></strong> " + thisText;
					newHTML += " <span class='lowpriority '>"
					newHTML += differanceText + " ";
					newHTML += '<a onclick=\"window.open(this.href);return false;\" onkeypress=\"window.open(this.href);return false;\" href="http://twitter.com/intent/tweet?in_reply_to='+thisData.id_str+'">Reply</a>&nbsp;<span>|</span>&nbsp;';
					newHTML += '<a onclick=\"window.open(this.href);return false;\" onkeypress=\"window.open(this.href);return false;\" href="http://twitter.com/intent/retweet?tweet_id='+thisData.id_str+'">Retweet</a>&nbsp;<span>|</span>&nbsp;';
					newHTML += '<a onclick=\"window.open(this.href);return false;\" onkeypress=\"window.open(this.href);return false;\" href="http://twitter.com/intent/favorite?tweet_id='+thisData.id_str+'">Favorite</a>';
					newHTML += "</span></p>";
				}
				$j('#TwitterFeed').html(newHTML);
			}
		});
	}
	
	if($j('#intmap').length > 0) {
		var lis = $j('#intmap').find('li');
		var newHTML = "";
		lis.each(function() {
			var titletext = $j(this).children('span').children('span').html();
			var pos = $j(this).attr('rel').split(',');
			newHTML += '<div class="hotspot" id="'+$j(this).attr('id')+'_spot" rel="'+$j(this).attr('id')+'" title="'+titletext+'" style="left:'+pos[0]+'px;top:'+pos[1]+'px"></div>'
		}).hover(function() {
			$j(this).addClass('active');
			$j('#'+$j(this).attr('id')+'_spot').addClass('hotspotactive');
		}, function() {
			$j(this).removeClass('active');
			$j('#'+$j(this).attr('id')+'_spot').removeClass('hotspotactive');
		});
		$j('#intmap').prepend(newHTML);
		$j('.hotspot').hover(function() {
			$j(this).addClass('hotspotactive');
			$j('#'+$j(this).attr('rel')).addClass('active');
		}, function() {
			$j(this).removeClass('hotspotactive');
			$j('#'+$j(this).attr('rel')).removeClass('active');
		});
	}
	
	if($j('.greyform').length > 0) {
		$j('.ErrorLabel').parents('.revealForm').show();
		$j('.successLabel').parents('.revealForm').show();
		$j('.greyform').find('input[type="checkbox"]').change(function() {
			var input = $j(this);
			var label = $j(this).next('label');
			if(label.length == 0) {
				label = input.parents('.EditingFormControlNestedControl').next('label');
			}
			if(this.checked) {
				label.css('color','#ec008c');
			} else {
				label.css('color','#000');
			}
		})
		
		if($j('#panelSelector').length > 0) {
			$j('#step5').find('h2 span.hlgt:first').html('5.');
			var count = 2;
			$j('#panelSelector').find('input').each(function() {
				if(count < 5) {
					$j(this).attr('rel','#step'+count);
					count++;
				}
			}).change(selectQueryPanels);
			selectQueryPanels();
		}
		$j('.req').find('input').focus(positionFormArrow).change(positionFormArrow);
		$j('.greyform').find('input[type="image"]').click(function() {
			if($j('.revealForm:visible').length > 0) {
				if($j('.revealForm:visible').find('textarea').val().length == 0) {
					$j('.revealForm:visible').find('textarea').focus();
					return confirm("Are you sure you wish to submit will no additional information?")
				} else {
					return true;
				}
			} else {
				if($j('.greyform').find('textarea').val().length == 0) {
					$j('.greyform').find('textarea').focus();
					return confirm("Are you sure you wish to submit will no additional information?")
				} else {
					return true;
				}
			}
		});
		$j('.numonly').find('input').keypress(numbersonly).keydown(numbersonly).keyup(numbersonly).blur(numbersonly);
		positionFormArrow();
		$j('.pwpanel').find('a.go').click(function() { 
			$j('.pwpanelactive').removeClass('.pwpanelactive');
			myTgt = $j(this).parents('.pwpanel').addClass('.pwpanelactive').attr('rel');
			if($j('#'+ myTgt).length > 0) {
				if($j('.revealForm:visible').length > 0) {
					$j('.revealForm:visible').fadeOut(750, function() { $j('#'+ myTgt).fadeIn(750, flashgform) });
				} else {
					$j('#'+ myTgt).fadeIn(750, flashgform);
				}
				return false;
			}
		}).hover(function() {
			$j(this).parents('.pwpanel').addClass('pwpanelhover');
		}, function() {
			$j(this).parents('.pwpanel').removeClass('pwpanelhover');
		});
	}
});

function flashgform() {
	gform = $j('.greyform:visible');
	gform.animate({backgroundColor:'#EC008C'} , 250, function() {
		gform = $j('.greyform:visible');
		gform.animate({backgroundColor:'#E4E4E4'} , 250);
	});
}

function numbersonly() {
	var regxp = new RegExp('([^0-9])', 'gi');
	var thisIn = $j(this);
	var myVal = thisIn.val(); 
	thisIn.val(myVal.replace(regxp, ''));
}

function positionFormArrow() {
	gform = $j('.greyform:visible');
	panels = gform.find('.panel:visible');
	if(gform.length > 0) {
		var pos;
		panels.find('.req').each(function() {
			pnl = $j(this);
			if(pnl.hasClass('chk')) {
				if(pnl.find('input:checked').length < 1) {
					pos = pnl.parents('.panel').position();
					return false;
				}	
			} else {
				if(pnl.find('input').val() == "") {
					pos = pnl.parents('.panel').position();
					return false;
				}
			}
		});
		if(typeof pos == "object") {
			gform.children('.arrow').animate( {'top':(pos.top +20)+'px'}, 500);
		} else {
			pos = gform.find('.panel:visible:last').position();
			gform.children('.arrow').animate( {'top':(pos.top +20)+'px'}, 500);
		}
	}
}

function selectQueryPanels() {
	$j('#panelSelector').find('input').each(function() {
		var input = $j(this);
		if(this.checked && typeof input.attr('rel') == "string") {
			$j(input.attr('rel')).show();
		} else {
			$j(input.attr('rel')).hide();
		}
	});
	var count = 1;
	var visiPanels = $j('#panelSelector').parents('.greyform').find('.panel');
	visiPanels = $j.grep(visiPanels, function(a,b) { 
		return a.style.display == 'block' || a.style.display == '';
	});
	$j(visiPanels).find('h2').each(function() {
		$j(this).children('span.hlgt:first').html(count +'.');
		count++;
	});
	//Cufon.replace('.panel h2 span.hlgt');
	positionFormArrow();
}

function getTimeFromTwStr(dateString) {
	dateArray = dateString.split(/[ :]/);
	thisDate = new Date(dateArray[7], monthIndex(dateArray[1]), dateArray[2], dateArray[3], dateArray[4], dateArray[5], 0);
	return thisDate
}

function dateDifferance(date1,date2) {
	time = (date1.getTime() - date2.getTime())/1000;
	if(time < 60) {
		return Math.floor(time) + "&nbsp;seconds&nbsp;ago";
	} else if (time < 60*60) {
		return Math.floor(time/60) + "&nbsp;minutes&nbsp;ago";
	} else if (time < 60*60*24) {
		return Math.floor((time/60)/60) + "&nbsp;hours&nbsp;ago";
	} else if (time < 60*60*24*30) {
		return Math.floor(((time/60)/60)/24) + "&nbsp;days&nbsp;ago";
	} else if (time < 60*60*24*30*12) {
		return Math.floor((((time/60)/60)/24)/30) + "&nbsp;months&nbsp;ago";
	} else {
		return Math.floor(((((time/60)/60)/24)/30)/12) + "&nbsp;years&nbsp;ago";
	}
}

function levelDivs() {
	$j('.trds, .qtrs, .nstrds, .nsqtrs').each( function() {
		var children = $j(this).children('.trd, .qtr');
		var highestHeight = 0;
		children.each( function() {
			if($j(this).height() > highestHeight) {
				highestHeight = $j(this).height();
			}
		});
		children.each( function() {
			if($j(this).height() < highestHeight) {
				var item = $j(this);
				var btn =item .find('.btn:last');
				if(btn.length > 0) {
					btn.css('margin-top',(highestHeight - item.height()) + "px");
				} else if(item.find('.inPack:last').length > 0) {
					$j(this).find('.inPack:last').css('margin-bottom',(highestHeight - item.height()) + "px!important");
				} else if(item.find('h4').length > 0){ 
					$j(this).find('h4:first').css('margin-top',(highestHeight - item.height()) + "px");
				} else {  
					var thisbr = item.find('.br:first');
					if(thisbr.parents('.btn, .pbtn').length > 0) {
						thisbr = thisbr.parents('.padding:first');
					}
					if(item.parents('.septoffer').length == 0 || thisbr.children('.clear').length == 0) {
						thisbr.append('<div class="clear"></div>');
					}
					thisbr.children('.clear:last').css('height',(highestHeight - item.height()) + "px")
				}
			}
		});
	});
}

function getSlide() {
	xhr = $j.ajax(
	{
	  type: "GET",
	  url: $j('.movingHeader').children('.loadingImg').children('img').attr('src'),
	  complete: function() {
		changeHeaderImage();
	  }
	});
}

function changeHeaderImage() {
	$j('.movingHeader').children('.activeImg').removeClass('activeImg').addClass('lastImg');
	var myImage = $j('.movingHeader').children('.loadingImg').addClass('activeImg').removeClass('loadingImg');
	var stats = myImage.attr('rel').split(',');
	myImage.css({'left':stats[0]+"px", 'top':stats[1]+"px", 'opacity':'0'});
	myImage.animate({'opacity':'1'},{ "duration":1500, "queue": false, "complete":function() { 
		var loading = $j(this).parent().children('.loadingImg');
		if(loading.length < 1) {
			$j(this).parent().children('.lastImg').removeClass('lastImg').css('opacity','0'); 
		} else {
			$j(this).parent().children('.lastImg').removeClass('lastImg').addClass('.loadingImg').css('opacity','0'); 
		}
	} });
	myImage.animate({'left':stats[2], 'top':stats[3]},{ "duration":10000, "easing":"linear"});
	if(stats.length > 4) {
		myImage.parent().attr('className', 'movingHeader ' + stats[4]);
	}
	setTimeout("getSlide()",8500);
	var loaderImg = myImage.next('.image');
	if(loaderImg.length < 1) {
		loaderImg = myImage.siblings('.image').first();
	}
	if(!loaderImg.hasClass("lastImg")) {
		loaderImg.addClass('loadingImg');
		loaderImg.css('opacity','0');
	};
}

function moveOneLeft() {
	clearInterval(myInterval);
	activeGallery = $j(this).parents('.gallery');
	$j('.gallery_contents').stop(true,true);
	targetIndex = null;
	moveLeft();
}

function moveOneRight() {
	clearInterval(myInterval);
	activeGallery = $j(this).parents('.gallery');
	$j('.gallery_contents').stop(true,true);
	targetIndex = null;
	moveRight();
}

function moveLeft() {
	if(typeof targetIndex != 'number') {
		activeGallery.find('.gallery_contents').each(function() {
			var contents = $j(this);
			var gallerystep = parseInt(contents.parents('.gallery').attr('gallerystep'));
			var currentLeft = parseInt(contents.parents('.gallery').attr('currentLeft'));
			var lis = contents.find('li');
			if(lis.length > gallerystep) {
				var pageWidth = contents.parent().attr('offsetWidth');
				
				var selectedIndex = parseInt(contents.find('li[class="active"]').attr('index'));
				
				var nextIndex = selectedIndex - gallerystep;
				if(nextIndex < 0) 
					nextIndex += lis.length;
				var thisItem = contents.find('li[index="'+nextIndex+'"]');
				lis.removeClass('active');
				thisItem.addClass('active');
				
				var leftElement = contents.find('li[index="'+selectedIndex+'"]');
				if((leftElement.position().left - pageWidth) <= thisItem.position().left) {
					for(var i=0;i<gallerystep;i++) {
						contents.find('ul').prepend(contents.find('li:last').detach());
					}
					contents.css('margin-left',(currentLeft - pageWidth) +"px");
				} else {
					currentLeft += pageWidth;
				}
				contents.parents('.gallery').attr('currentLeft', currentLeft)
				contents.stop(false, false).animate( { marginLeft: currentLeft +"px" }, 300, function() {
					var myIndex = activeGallery.find('li.active').attr('index');
				});
			}
		});
	}
}

function moveRight() {
	if(typeof targetIndex != 'number') {
		activeGallery.find('.gallery_contents').each(function() {
			var contents = $j(this);
			var gallerystep = parseInt(contents.parents('.gallery').attr('gallerystep'));
			var currentLeft = parseInt(contents.parents('.gallery').attr('currentLeft'));
			var lis = contents.find('li');
			if(lis.length > gallerystep) {
				var pageWidth = contents.parent().attr('offsetWidth');
				var selectedIndex = parseInt(contents.find('li[class="active"]').attr('index'));
				
				var nextIndex = selectedIndex + gallerystep;
				if(nextIndex > lis.length-1) 
					nextIndex -= lis.length-1;
				var thisItem = contents.find('li[index="'+nextIndex+'"]');
				
				lis.removeClass('active');
				thisItem.addClass('active');
				if(thisItem.position().left >= pageWidth) {
					currentLeft -= pageWidth;
					$j(this).parents('.gallery').attr('currentLeft', currentLeft);
					contents.stop(false, false).animate( { marginLeft: currentLeft +"px" }, 300, function() {
						var currentLeft = parseInt($j(this).parents('.gallery').attr('currentLeft'));
						var gallerystep = parseInt($j(this).parents('.gallery').attr('gallerystep'));
						var activeElement = $j(this).find('li[class="active"]');
						var nextIndex = parseInt(activeElement.attr('index'))-gallerystep;
						if(nextIndex < 0)
							nextIndex += lis.length;
						var leftElement = $j(this).find('li[index="'+nextIndex+'"]');
						if(leftElement.position().left < activeElement.position().left) {
							for(var i=0;i<gallerystep;i++) {
								$j(this).find('ul').append(contents.find('li:first').detach());
								currentLeft += activeElement.attr('offsetWidth');
							}
							$j(this).css('margin-left',currentLeft +"px");
						}
						
						$j(this).parents('.gallery').attr('currentLeft', currentLeft);
						var myIndex = activeGallery.find('li[class="active"]').attr('index');
					});
				} else {
					contents.css('margin-left',(currentLeft+pageWidth) +"px");
					for(var i=0;i<gallerystep;i++) {
						contents.find('ul').append(contents.find('li:first').detach());
					}
					contents.stop(false, false).animate( { marginLeft: currentLeft +"px" }, 300, function() {
						var myIndex = activeGallery.find('li.active').attr('index');
					});
				}
			}
		});
	}
}

function monthIndex(monthTitle) {
    for (var i = 0; i < month.length; i++) {
        if(month[i] == monthTitle)
            return i
    }
    return 0;
}

var month = new Array(12);
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sep";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";

function switchFaderImages() {
	$j(faderSections).each(function() {
		var activeImg = $j(this).children('.activeImg').removeClass('activeImg').addClass('lastImg');
		var loaderImg = activeImg.next('img, a');
		if(loaderImg.length < 1) {
			loaderImg = $j(this).children('img,a').first();
		}
		loaderImg.addClass('loadingImg').show().css('opacity',0);
		loaderImg.animate({'opacity':1},1500, function() {
			$j(this).parent().children().removeClass('activeImg').removeClass('loadingImg').removeClass('lastImg');
			$j(this).addClass('activeImg');
		});
	});
}

function switchHomeFaderImages() {
		var homeFader = $j('.homeFader');
		var activeImg = homeFader.children('.activeImg').removeClass('activeImg').addClass('lastImg');
		var loaderImg = activeImg.next('img, a');
		if(loaderImg.length < 1) {
			loaderImg = homeFader.children('img,a').first();
		}
		loaderImg.addClass('loadingImg').show().css('opacity',0);
		loaderImg.animate({'opacity':1},1500, function() {
			$j(this).parent().children().removeClass('activeImg').removeClass('loadingImg').removeClass('lastImg');
			$j(this).addClass('activeImg');
			
			var myIndex = homeFader.children('img, a').index($j(this));
			setTimeout("switchHomeFaderImages()", 5000);
		});
}

function clearCheck(myInput, defaultText)
{
    if (myInput.value == defaultText) {
        myInput.value = "";
    }
}


function iotbs() {
	switcher = new switchManager();
};

var switcher;


//preferences manager
function switchManager() {
	//string for storing the overall custom classname
	//I was originally storing it in the body class name directly
	//but 1.7+ mozilla builds were not honouring the trailing whitespace we need
	this.string  = '';

	//store reference to body element
	this.body = document.getElementsByTagName('body')[0];

	//store the initial classname
	this.initial = this.body.className;

	//if the default classname is empty, add "iotbs"
	//because we need there to be at least one classname already -
	//the leading and trailing space in each custom classname is required,
	//but you can't set the body classname as " something" (beginning with a leading space)
	//because that may not work in Opera 7
	if(this.initial == '') {
		this.initial = 'itobs';
	}

	//look for a stored cookie
	this.cookie = this.read();

	//if it exists
	if(this.cookie != null) {
		//store cookie value to string
		this.string = this.cookie;

		//set new body class name
		this.body.className = this.initial + ' ' + this.string;
	}

	//*** dev
	//document.title = '<' + this.body.className.replace(/ /g,'+') + '>   [' + this.string.replace(/ /g,'+') + ']';
};

//set a cookie method
switchManager.prototype.set = function(days) {
	//format expiry date
	this.date = new Date();
	this.date.setTime(this.date.getTime() + ( days *24*60*60*1000));

	//store the string, replacing spaces with '#' so that leading spaces are preserved
	this.info = this.string.replace(/ /g,'#');

	//if the value is empty, set its expiry in the past to delete the cookie
	if(this.info == '') { this.date.setTime(0); }

	//create the cookie
	document.cookie = 'bodySwitcher=' + this.info
		+ '; expires=' + this.date.toGMTString()
		+ '; path=/';
};


//read a cookie method
switchManager.prototype.read = function() {
	//set null reference so we always have something to return
	this.cookie = null;

	//if a cookie exists
	if(document.cookie) {
		//if it's our cookie
		if(document.cookie.indexOf('bodySwitcher')!=-1) {
			//extract and store relevant information (turning '#' back into spaces)
			this.cookie = document.cookie.split('bodySwitcher=');
			this.cookie = this.cookie[1].split(';');
			this.cookie = this.cookie[0].replace(/#/g,' ');
		}
	}
	return this.cookie;
};


function changetoDefault() {
	if(switcher) {
		switcher.string = 'default'
		switcher.body.className = " iotbs  ";
		switcher.set(365);
		levelDivs();
	}
}

function changetoMedium() {
	if(switcher) {
		switcher.string = 'medium';
		switcher.body.className = " iotbs  " + switcher.string +' ';
		switcher.set(365);
		levelDivs();
	}
}

function changetoLarge() {
	if(switcher) {
		switcher.string = 'large';
		switcher.body.className = " iotbs  " + switcher.string +' ';
		switcher.set(365);
		levelDivs();
	}
}
