/*
 * $Revision: 145 $
 * $Author: Mike $
 */
 
jQuery(function($) {
 
	var Engine = {
		// navigation scripts
		navigation : {
			// keyboard accessibility
			keyboardAccessibility : function(){
				$('#navigation a').focus(function(){
					$(this).css('text-decoration','underline');
					$(this).parents('ul').eq(0).addClass('over');
					$(this).parent('li').find('ul').eq(0).addClass('over');
				}).blur(function(){
					$(this).css('text-decoration','none');
					$(this).parents('ul').eq(0).removeClass('over');
					$(this).parent('li').find('ul').eq(0).removeClass('over');
				});
			}
		},
		// article scripts
		article : {
			// comment chars counter and limit
			commentCounter : function(){
				if($('#postComment fieldset textarea').size() < 1) return false;
				
				var charLimit 	= 1000;
				var code 		= ', left: <span class="limit">' + (charLimit - $('#postComment fieldset textarea').val().length) + '</span>';
				
				$('#postComment p.limit-info').append(code);
				
				$('#postComment fieldset textarea').keyup(function(){
					$('#postComment span.limit').html((charLimit - $(this).val().length));
					if($(this).val().length > charLimit){
						$('#postComment span.limit').addClass('warning');
					} else {
						$('#postComment span.limit').removeClass('warning');
					}
				});
			},
			// article tools: print, font size
			fontSize : function(){
				$('ul.articleTools')
					//.find('li.share').after('<li class="print"><a href="#print">Print</a></li>').end()
					//.find('li.print a').click(function(){ window.print(); return false; }).end()
					.find('li.email').after('<li class="fonts">Text Size <ul><li><a href="#font-normal" class="a">Normal</a></li><li><a href="#font-large" class="aa">Large</a></li><li><a href="#font-xlarge" class="aaa">Extra Large</a></li></ul></li>').end()
					.find('li.fonts a').click(function(){
						switch ($(this).attr('class')) {
							case 'aaa': var value = 'aaa'; break;
							case 'aa': var value = 'aa'; break;
							default: var value = 'a'; break;
						}		
						$.cookie('fontsizeAAA', value, { expires: 90, path: '/'});
						$('#article div.body').attr('class','body font-'+$(this).attr('class'));
						return false;
					});
				
				if($('#article').size() == 1 && $.cookie('fontsizeAAA') != 'null'){
					$('#article div.body').attr('class','body font-'+$.cookie('fontsizeAAA'));
				}
			}
		},
		// section specific
		specific : {
			// family announcement search
			announcementsSearch : function(){
				if($('#announcementsSearch').size() > 0){
					var root = $('#announcementsSearch');
					
					root.find('h2:first').after('<p class="switch"><a href="#switch"><span>Show</span> advanced search</a></p>').end()
						.find('p.switch a').toggle(function(){
							root.removeClass('simple').find('p.switch a span').text('Hide');
							return false;
						},function(){
							root.addClass('simple').find('p.switch a span').text('Show');
							return false;
						});
						
					root.find('input.datepicker').datepicker({showOn: "both", dateFormat: "dd/mm/yy", showAnim: "fadeIn", speed: "fast", buttonImage: "http://announcements.independent.ie/images/i_datepicker-b.gif", buttonImageOnly: true})
				}
			},
			// newsletter profiles parent checkboxes
			profilesCheckgroups : function(){
				$('#enewsletters div.interests ul > li > input[type=checkbox]').click(function(){
					if($(this).attr('checked') === true){
						$(this).parent().find('ul li input[type=checkbox]').attr('checked','checked');
					} else {
						$(this).parent().find('ul li input[type=checkbox]').removeAttr('checked');
					}
					$(this).focus();
				});
			},
			// advanced search date range disable/enable
			advancedSearch : function(){
				if($('#advs-daterange-5').attr('checked') != true){
					$('#advancedSearch fieldset div.radios div.dates select').attr('disabled','disabled');
				}
				$('#advancedSearch span.datechange input').focus(function(){
					if($(this).attr('id') == 'advs-daterange-5'){
						$('#advancedSearch fieldset div.radios div.dates select').attr('disabled','');
					} else {
						$('#advancedSearch fieldset div.radios div.dates select').attr('disabled','disabled');
					}
				});
			},
			// travel autocomplete
			travelDestinations : function(){
				if (typeof airports != 'undefined' && typeof cities != 'undefined'){
					$("#indoTravel")
						.find("input[@name=td_dest]").autocomplete(airports,{matchContains: true}).end()
						.find("input[@name=td_market], input[@name=td_pickup], input[@name=td_dropoff]").autocomplete(cities,{matchContains: true})
					;
				}
			}
		},
		// other elements
		other : {
			// tabbed container #1
			tabbedContainer : function(){
				$('div.tabbedContainer').not('.regular').each(function(){
					var cont = $(this);
					if(cont.find('ul.anchors li.tabs-selected').size() == 0){
						cont.find('ul.anchors li:first-child').addClass('tabs-selected');
					}
					cont.find('ul.anchors li a').click(function(){
						cont.find('ul.anchors li').removeClass('tabs-selected');
						$(this).parent('li').addClass('tabs-selected');
						
						cont.find('>div:visible').hide();
			            var re = /([_\-\w]+$)/i;
			            $('#' + re.exec($(this).attr('href'))[1]).show();
						
						return false;
					});
				});
			},
			// tabbed container #2
			tabIt : function(){
				$('div.tabIt').each(function(i){
					var parent = $(this);
					parent.prepend('<ul class="index"></ul>');
					var tabIndex = parent.find('ul.index');
					parent.find('div.section').each(function(z){
						$(this).find('h2').attr('id','tab-'+i+'-'+z);
						tabIndex.append('<li' + (z == 0 ? ' class="selected"' : '') + '><a href="#tab-' + i + '-' + z + '">' + $(this).find('h2').text() + '</a></li>')
						if(z > 0) $(this).hide();
					});
					tabIndex.find('li a').click(function(){
						tabIndex.find('li').removeClass('selected');
						$(this).parent().addClass('selected');
						parent.find('div.section').hide();
						var id = $(this).attr('href').split('#'); id = '#' + id[1];
						parent.find(id).parent().show();
						return false;
					});
				});
			},
			// default value for search inputs
			searchLabel : function(){
				var label = 'Search';
				$('fieldset.searchBox span.mainInput input').each(function(){
					if($(this).val() === '') $(this).val(label);
					$(this).focus(function(){
						if($(this).val() == label) $(this).val('');
					})
				});
				
				$('label.v').next('input').each(function(){
					if($(this).val() !== '') $(this).prev('label.v').hide();
					$(this).focus(function(){
						$(this).prev('label.v').hide();
					}).blur(function(){
						if($(this).val() === '') $(this).prev('label.v').show();
					});
				});
			},
			// png24 ie6 fix
			png24ie : function(){
				if($.browser.msie && $.browser.version.substr(0,1) == '6'){
					$('img').each(function(){
						if($(this).attr('src').indexOf('24.png') >= 0){
							$(this)
								.css('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+$(this).attr('src')+'\', sizingMethod=\'scale\')')
								.attr('src','images/blank.gif');
						}
					});
				}
			},
			// yahoo ads eqHeight
			yahoosHeight : function(){
				$('div.yahoo-wrap-a div.yahoos-b').eqHeight();
				$('#mainColumn div.yahoos-b div.wrapper, #secondaryColumn div.yahoos-b div.wrapper').each(function(){
					$(this).find('h3').eqHeight();
				});
			},
			ajaxPoll : function(){
				$('div.poll-a').each(function(){
					var root = $(this);
					root.find('form').submit(function(){
						if($(this).find('input:checked').size() == 0) return false;
						
						var name 	= $(this).find('input:checked').attr('name');
						var value 	= $(this).find('input:checked').val();
						
						root.find('div.poll').prepend('<p class="loading">Loading please wait</p>');
						root.find('p.loading').height(root.find('div.poll').height()).css('opacity',0).fadeTo(300,0.8,function(){
							$.post("./", { name: name, value: value }, function(){
								root.find('div.poll').fadeOut(500,function(){
									root.find('div.results ul.results li span span').width(0).find('strong').hide();
									root.find('div.results').fadeIn(300,function(){
										root.find('div.results ul.results li span span').each(function(){
											$(this).animate({width: $(this).find('strong').html()}, 1500).find('strong').fadeIn(500);
										});
									});
								});
							});
						});
						return false;
					});
				});
			},
			indoTravel : function(){
				var root = $('#indoTravel');
				
				// datepicker
				root.find('input.calendar').attr('autocomplete','off').datepicker({showOn: "focus", minDate: 0, dateFormat: "dd/mm/yy", showAnim: "fadeIn", speed: "fast"})

				// return off
				if(root.find('input#it-102').is(':checked')){
					root.find('input#it-107, select#it-107b').attr('disabled','disabled');
				}
				
				var evt = $.browser.msie ? "click" : "change";
				root.find('input#it-102').bind(evt,function(){
					root.find('input#it-107, select#it-107b').attr('disabled','disabled');
				});
				root.find('input#it-101').bind(evt,function(){
					root.find('input#it-107, select#it-107b').removeAttr('disabled');
				});
				
				// children
				root.find('select.children').bind(evt,function(){
					var childroot = $(this).parent().parent().next('div.children');
					var children = $(this).val();
					if(children > 0){
						childroot.find('p.child').hide().slice(0,children).show();
						childroot.show();
					} else {
						childroot.hide();
					}
				});
				
				root.find('select.children').trigger(evt);
			},
			photoUpload : function(){
				var root = $('#uploadPhoto');
				root.find('input.datepicker').attr('autocomplete','off').datepicker({showOn: "focus", dateFormat: "dd/mm/yy", showAnim: "fadeIn", speed: "fast"});
			}
		},	
		// sliders
		sliders : { 
			// entertainment
			entertainment : {
				time : 10000,
				slide : function(){
					$('#entertainment ul.paging li.next a').trigger('click');
					Engine.sliders.entertainment.timeout = setTimeout(Engine.sliders.entertainment.slide,Engine.sliders.entertainment.time);
				},
				init : function(){
					var slidesCurrent 	= 1;
					var slidesCount 	= $('#entertainment ul.slides').size();
					var slidesWidth 	= $('#entertainment div.slidesHolder').width();
					
					if(slidesCount > 1){
						// cloning
						$('#entertainment div.slidesHolder').addClass('slidesHolderCSS').before('<ul class="paging"><li class="prev"><a href="./" title="Previous">&laquo;</a></li><li class="pause"><a href="./" title="Pause">&bull;</a></li><li class="next"><a href="./" title="Next">&raquo;</a></li></ul>');
						$('#entertainment ul.slides:last').clone().prependTo("#entertainment div.slidesHolder");
						$('#entertainment ul.slides').eq(1).clone().appendTo("#entertainment div.slidesHolder");
						
						// positioning
						$('#entertainment ul.slides').each(function(i){
							var leftPosition = (slidesWidth * i) - slidesWidth;
							$(this).css({ position: "absolute", width: "100%", top: "0", left: leftPosition });
						});
						
						// click: previous 
						$('#entertainment ul.paging li.prev a').click(function(){
							if(parseInt($('#entertainment ul.slides').eq(0).css("left")) % slidesWidth == 0){
								if(slidesCurrent == 0){
									$('#entertainment ul.slides').each(function(){
										var newLeftPosition = parseInt($(this).css("left"),10) - slidesCount * slidesWidth;
										$(this).css('left',newLeftPosition);
									});
									slidesCurrent = slidesCount;
								}
								
								$('#entertainment ul.slides').each(function(){
									var newLeftPosition = parseInt($(this).css("left"),10) + slidesWidth;
									$(this).animate( { left: + newLeftPosition + 'px' }, 'slow' );
								});
								slidesCurrent--;
							}
							return false;
						});
						
						// click: next
						$('#entertainment ul.paging li.next a').click(function(){
							if(parseInt($('#entertainment ul.slides').eq(0).css("left")) % slidesWidth == 0){
								if(slidesCurrent == slidesCount+1){
									$('#entertainment ul.slides').each(function(){
										var newLeftPosition = parseInt($(this).css("left"),10) + slidesCount * slidesWidth;
										$(this).css('left',newLeftPosition);
									});
									slidesCurrent = 1;
								}
								
								$('#entertainment ul.slides').each(function(){
									var newLeftPosition = parseInt($(this).css("left"),10) - slidesWidth;
									$(this).animate( { left: + newLeftPosition + 'px' }, 'slow' );
								});
								slidesCurrent++;
							}
							return false;
						});

						// click: pause
						Engine.sliders.entertainment.timeout = setTimeout(Engine.sliders.entertainment.slide,Engine.sliders.entertainment.time);
						
						$('#entertainment ul.paging li.pause a').toggle(function(){
							$(this).addClass('active');
							clearTimeout(Engine.sliders.entertainment.timeout);
							return false;
						},function(){
							$(this).removeClass('active');
							clearTimeout(Engine.sliders.entertainment.timeout);
							Engine.sliders.entertainment.timeout = setTimeout(Engine.sliders.entertainment.slide,Engine.sliders.entertainment.time);
							return false;
						});
						
					}
				}
			},
			// stories sliders
			stories : function(){
				$('div.storiesSlider').each(function(){
					var storiesCount = $(this).find('div.story').size();
					var storiesCurrent = 1;
					if(storiesCount > 1){
						$(this).append('<p class="index"><a href="#prev" class="prev">prev</a> <span>|</span> <strong>Story 1/' + storiesCount + '</strong> <span>|</span> <a href="#next" class="next">next</a></p>');
						$(this).find('div.story:gt(0)').hide();
						
						var box = $(this);
						
						$(this).find('p.index a').click(function(el){
							if(el.target.className == 'prev'){
								if(storiesCurrent > 1){
									box.find('div.story:eq('+(storiesCurrent-1)+')').prev().show().end().hide();
									storiesCurrent--;
								} else {
									box.find('div.story:eq('+(storiesCurrent-1)+')').hide();
									box.find('div.story:eq('+(storiesCount-1)+')').show();
									storiesCurrent = storiesCount;
								}
							} else if (el.target.className == 'next'){
								if(storiesCurrent < storiesCount){
									box.find('div.story:eq('+(storiesCurrent-1)+')').next().show().end().hide();
									storiesCurrent++;
								} else {
									box.find('div.story:eq('+(storiesCount-1)+')').hide();
									box.find('div.story:eq(0)').show();
									storiesCurrent = 1;
								}
							}
							box.find('p.index strong').html('Story '+storiesCurrent+'/'+storiesCount);
							return false;
						});
					}
				});
			},
			// editors choice
			editors : {
				time : 10000,
				slide : function(){
					$('#editorsSlider ul.paging li.next a').trigger('click');
					Engine.sliders.editors.timeout = setTimeout(Engine.sliders.editors.slide,Engine.sliders.editors.time);
				},
				init : function(){
					// equal height
					var editorHeight =  0;
					$('#editorsSlider ul.slides li').each(function(){
						currentHeight = $(this).height();
						if(currentHeight > editorHeight){
							editorHeight = currentHeight;
						}
					});
					$('#editorsSlider ul.slides li').css('height',editorHeight+'px');
					
					// slider engine
					var editorsCurrent 		= 1;
					var editorsCount 		= $('#editorsSlider ul.slides li').size();
					var editorsWidth 		= $('#editorsSlider').width()/4;
					var editorsContainer 	= editorsCount * editorsWidth;
					
					if(editorsCount > 4){
						// cloning
						$('#editorsSlider div.slidesWrap').height(editorHeight+16).before('<ul class="paging"><li class="prev"><a href="./">&laquo;</a></li><li class="pause"><a href="./">pause</a></li><li class="next"><a href="./">&raquo;</a></li></ul>');
						$('#editorsSlider ul.slides li').clone().appendTo("#editorsSlider ul.slides").clone().appendTo("#editorsSlider ul.slides");
						
						// positioning
						var leftPosition = editorsWidth * editorsCount * -1;
						var fullWidth = editorsCount * editorsWidth * 3;
						$('#editorsSlider ul.slides').css({ position: "absolute", top: "0", left: leftPosition, width: fullWidth });
						
						$('#editorsSlider ul.paging li.prev a').click(function(){
							var position = parseInt($('#editorsSlider ul.slides').css("left"));
							if (position % editorsWidth == 0 && $('#editorsSlider ul.slides:animated').size() == 0){
								if(position >= -editorsContainer){
									$('#editorsSlider ul.slides').css('left',(position - editorsContainer));
									position = parseInt($('#editorsSlider ul.slides').css("left"));
								}
								$('#editorsSlider ul.slides').animate( { left: position+editorsWidth }, 350);
							}
							return false;
						});

						// click: next
						$('#editorsSlider ul.paging li.next a').click(function(){
							var position = parseInt($('#editorsSlider ul.slides').css("left"));
							if (position % editorsWidth == 0 && $('#editorsSlider ul.slides:animated').size() == 0){
								if(position <= -editorsContainer){
									$('#editorsSlider ul.slides').css('left',(position + editorsContainer));
									position = parseInt($('#editorsSlider ul.slides').css("left"));
								}
								$('#editorsSlider ul.slides').animate( { left: (position-editorsWidth) }, 350);
							}
							return false;
						});
						
						// click: pause
						Engine.sliders.editors.timeout = setTimeout(Engine.sliders.editors.slide,Engine.sliders.editors.time);
						
						$('#editorsSlider ul.paging li.pause a').toggle(function(){
							$(this).addClass('active');
							clearTimeout(Engine.sliders.editors.timeout);
							return false;
						},function(){
							$(this).removeClass('active');
							clearTimeout(Engine.sliders.editors.timeout);
							Engine.sliders.editors.timeout = setTimeout(Engine.sliders.editors.slide,Engine.sliders.editors.time);
							return false;
						});
					}
					
					// hover
					$('#editorsSlider ul.slides li a').hover(function(){
						$(this).parent('li').addClass('over');
					},function(){
						$(this).parent('li').removeClass('over');
					});
				}
			},
			// generic carousell a
			a : {
				init : function(){
					var root 		= this;
					var elements 	= 'div.featured-a';
					root.data 		= [];
					
					$(elements).each(function(id,el){
						// global and local data
						root.data[id] 	= {};
						var main 		= root.data[id].main 		= $(this);
						var settings 	= root.data[id].settings 	= $(this).data('settings') || {};
						var wrapper		= root.data[id].wrapper		= main.find('.wrapper');
						var slider		= root.data[id].slider 		= main.find('.slides');
						var width		= root.data[id].width 		= settings.width || wrapper.width();
						var count		= root.data[id].count		= slider.children().size();
						var page		= root.data[id].page		= 1;
						var animate 	= root.data[id].animate		= settings.animate || 600;
						var hold		= root.data[id].hold 		= settings.hold || 10000;
						
						// break if there is just one item
						if(count < 2) return;
						
						// extra elements + proper width of the container
						slider.children().filter(":last").clone().prependTo(slider);
						slider.children().filter(":eq(1)").clone().appendTo(slider);
						slider.width((count+2)*width).css('margin-left',-width);
						
						// insert next/pause/prev links
						wrapper.before('<ul class="paging"><li class="prev"><a href="./">previous</a></li><li class="pause"><a href="./">pause</a></li><li class="next"><a href="./">next</a></li></ul>');
						
						// triggers
						main.find('ul.paging li a').click(function(){
							if($(this).parent().hasClass('pause')){
								if($(this).hasClass('active')){
									$(this).removeClass('active');
									root.data[id].stop = 0;
								} else {
									$(this).addClass('active');
									root.data[id].stop = 1;
								}
							} else {
								root.move(id,$(this).parent().attr('class'));
							}
							return false;
						});
						
						// autoslide
						root.data[id].timeout = setInterval(function(){Engine.sliders.a.interval(id)},hold+animate);
					});
				},
				move : function(id,direction){
					var root = this;
					
					if(root.data[id].slider.is(':animated')) return;
					
					if(direction == "prev"){
						if(root.data[id].page == 1){
							root.data[id].page = root.data[id].count+1;
							root.data[id].slider.css('margin-left',-(root.data[id].count+1)*root.data[id].width);
						}	
						root.data[id].page = root.data[id].page - 1;
						var lenght	= "+="+root.data[id].width;
					} else {
						if(root.data[id].page == root.data[id].count){
							root.data[id].page = 0;
							root.data[id].slider.css('margin-left',0);
						}
						root.data[id].page = root.data[id].page + 1;
						var lenght = "-="+root.data[id].width;
					}
					
					root.data[id].slider.animate({marginLeft: lenght},root.data[id].animate);
				},
				interval : function(id){
					var root = Engine.sliders.a;
					if(root.data[id].stop != 1) root.data[id].main.find('ul.paging li.next a').trigger('click');
				}
			},
			// sponsors
			sponsors : {
				init : function(){
					var root 		= this;
					this.component 	= $('#sponsoredFeatures');
					this.slider 	= this.component.find('div.items');
					this.count	 	= this.slider.find('div.item').size();
					this.width	 	= this.slider.width();
					this.hold		= 6000;
					this.animate	= 600;
					
					if(this.count < 2) return false;
					code = '<ul class="index"><li class="prev"><a href="#prev" title="Previous">Previous</a></li><li class="next"><a href="#next" title="Next">Next</a></li></ul>';
					this.component.find('h2').after(code);
					
					this.page = 1;
					this.slider.width(this.width*(this.count+2));
					this.slider.find('div.item:last').clone().prependTo(this.slider);
					this.slider.find('div.item:eq(1)').clone().appendTo(this.slider);
					this.slider.find('div.item').width(this.width).css('display','block');
					this.slider.css('margin-left',-this.width);
					
					this.component.find('ul.index li a').click(function(){
						root.move($(this).parent().attr('class'));
						return false;
					});
					
					root.timeout = setInterval(function(){Engine.sliders.sponsors.move()},root.hold+root.animate);
					this.component.bind('mouseenter',function(){
						clearInterval(root.timeout);
					}).bind('mouseleave',function(){
						root.timeout = setInterval(function(){Engine.sliders.sponsors.move()},root.hold+root.animate);
					});
				},
				move : function(direction){
					var root = this;
					if(this.slider.is(':animated')) return;
					
					if(direction == "prev"){
						if(this.page == 1){
							this.page = this.count+1;
							this.slider.css('margin-left',-(this.count+1)*this.width);
						}	
						this.page = this.page - 1;
						var lenght	= "+="+this.width;						
					} else {
						if(this.page == this.count){
							this.page = 0;
							this.slider.css('margin-left',0);
						}
						this.page = this.page + 1;
						var lenght = "-="+this.width;
					}
					
					this.component.find('div.sub li.active').removeClass('active');
					this.component.find('div.sub li:eq('+(this.page-1)+')').addClass('active');
					this.slider.animate({marginLeft: lenght},root.animate);
				}
			}
		}
	};
	
	// navigation
	Engine.navigation.keyboardAccessibility();
	
	// article
	Engine.article.commentCounter();
	Engine.article.fontSize();
	
	// specific
	Engine.specific.announcementsSearch();
	Engine.specific.profilesCheckgroups();
	Engine.specific.advancedSearch();
	Engine.specific.travelDestinations();
	
	// other
	Engine.other.tabbedContainer();
	Engine.other.tabIt();
	Engine.other.searchLabel();
	Engine.other.png24ie();
	Engine.other.yahoosHeight();
	Engine.other.ajaxPoll();
	Engine.other.indoTravel();
	Engine.other.photoUpload();
	
	// sliders
	Engine.sliders.entertainment.init();
	Engine.sliders.stories();
	Engine.sliders.editors.init();
	Engine.sliders.sponsors.init();
	Engine.sliders.a.init();
	
});

// NEWS TICKER

function runTheTicker(){
	var myTimeout;  
	
	// Go for the next story data block
	if(theCurrentLength == 0){
		theCurrentStory++;
		theCurrentStory		= theCurrentStory % theItemCount;
		theStorySummary		= theSummaries[theCurrentStory].replace(/&quot;/g,'"');		
		theTargetLink		= theSiteLinks[theCurrentStory];
		thePrefix 	     	= "<span>" +theHours[theCurrentStory] + "</span> ";
	}
	
	// Stuff the current ticker text into the anchor
	
	theTicker.innerHTML = 
		'<li><a href="' + theTargetLink +'">' +  thePrefix + theStorySummary.substring(0,theCurrentLength) + whatWidget() + '</a></li>';
	
	// Modify the length for the substring and define the timer
	if(theCurrentLength != theStorySummary.length){
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	} else {
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}

// Widget generator
function whatWidget(){
	if(theCurrentLength == theStorySummary.length) return ''; 
	if((theCurrentLength % 2) == 1){ return '_'; } else { return '-'; }
}

jQuery(function($) {
	if($('div.breakingTicker').size() > 0){
		theCharacterTimeout = 50;
		theStoryTimeout     = 5000;

		theSummaries 		= new Array();
		theHours 			= new Array();
		theSiteLinks 		= new Array();
		
		theTicker = $('div.breakingTicker ul').get(0);

		$('div.breakingTicker ul').addClass('loaded');
		
		$('div.breakingTicker ul li a').each(function(){
			theSummaries[theSummaries.length] = $(this).get(0).childNodes[1].nodeValue.replace(/^\s*|\s*$/g,"");
			theHours[theHours.length] = $(this).find('span').html();
			theSiteLinks[theSiteLinks.length] = $(this).attr('href');
		});

		theItemCount = theSummaries.length;
		theCurrentStory     = -1;
		theCurrentLength    = 0;

		runTheTicker();
	}
});

document.write('<link rel="stylesheet" type="text/css" media="screen" href="http://www.independent.ie/independent.ie/styles/javascript.css" />');
