/*
 * $Id: main.js,v 1.1.6.11.2.26 2010-09-29 09:30:31 byoung Exp $
 * NextGen main.js
 * Copyright (c) 2010 Orbis Technology Ltd. All rights reserved.
 */

$(function() {
	if ($('#TreeView').length > 0){
		$("#TreeView").find("li").has(".selected").addClass("open");
		$("#TreeView").treeview({
			animated: "fast",
			collapsed: true
		});
	}

	addHandlers();

});

function addHandlers() {
	/* To be extended by Orbis */
	/* Interface controls */
	if ($('input.date-pick').length > 0){
		$('input.date-pick').datePicker(
			{
				startDate: '01/01/2007',
				endDate: (new Date()).asString()
			}
		);
		$('#period_start').bind(
			'dpClosed',
			function(e, selectedDates)
			{
				var d = selectedDates[0];
				if (d) {
					d = new Date(d);
					$('#period_end').dpSetStartDate(d.addDays(0).asString());
				}
			}
		);
		$('#period_end').bind(
			'dpClosed',
			function(e, selectedDates)
			{
				var d = selectedDates[0];
				if (d) {
					d = new Date(d);
					$('#period_start').dpSetEndDate(d.addDays(0).asString());
				}
			}
		);
	}
	$('#Body div.goodcauses li a').click(function(e){
		e.preventDefault();
		$(this).blur();
		
		$('#Body div.goodcauses div.toggle').hide();
		$('#Body div.goodcauses .' + $(this).attr('name')).show();
		
		$('#Body div.goodcauses li').removeClass('current');
		$(this).parent().addClass('current');
	});
	$('#Timeline h4').click(function(){
		if (!$(this).parent().hasClass('current')){
			$('#Timeline li').removeClass('current');
			$('#Timeline div').hide('fast');
			$(this).parent().find('div').show('fast');
			$(this).parents('li').addClass('current');
		}
	});
	$("#Account div.balance a").click(function(e) {
		e.preventDefault();
		$(this).parent("div").find("table").toggle();
		$(this).text($(this).text() == 'Show Balances' ? 'Hide Balances' : 'Show Balances');
		$(this).toggleClass('open');
	});
	$("div.findRadio input").focus(function(e) {
		$(this).parents("div.findRadio").find("input[name=qry_type]").attr("checked", "checked");
	});
	$("div.findRadio select").focus(function(e) {
		$(this).parents("div.findRadio").find("input[name=qry_type]").attr("checked", "checked");
	});
	$("div.findRadio a.dp-choose-date").focus(function(e) {
		$(this).parents("div.findRadio").find("input[name=qry_type]").attr("checked", "checked");
	});
	$("#Body form.lost h3.header").click(function(e) {
		if ($(this).parents("form.lost").hasClass("closed")){
			$(this).parents("div#Body").find("div.content").hide("fast");
			$(this).parents("div#Body").find("form.lost").addClass("closed");
			$(this).parents("form.lost").find("div.content").show("fast");
			$(this).parents("form.lost").removeClass("closed");
		}
	});
	$("#Body a.triggerPanel").click(function(e) {
		var el = "#" + $(this).attr("name");
		var close = true;
		if ($(el).hasClass('noClose')){
			close = false;
		}
		showPanel(e, el, close);
	});
	$("#helpMenu a").click(function(e) {
		e.preventDefault();
		
		$(this).parents("ul#helpMenu").find("li").removeClass("current");
		$(this).parents("li").addClass("current");
		$(this).blur();
		
		var el = "div#" + this.className;
		$(this).parents("div#video").find("div.helpContent").hide();
		$(this).parents("div#video").find(el).show();
	});

	/* Leaderboard */
	if ($('#Leaderboard').length > 0){
		$('#Leaderboard .show li:first').addClass('first');
		var SetTotal = function(){
			var total = $('#Leaderboard .show li').length;
			$('ul.paging span.total').text(total);
		};
		SetTotal();

		// remove paging hrefs if not needed
		$('ul.paging.show a').each(function (e){
			var total = $(this).parent().siblings('li.page').find('span.total').text();
			// always remove the first/prev. Remove the last/next only if needed
			if ((total == 1) || $(this).hasClass('first') || $(this).hasClass('previous')) $(this).addClass('unclickable');
			// Mantis 994 Hide First/Prev/Next/Last if only 1 page of results
			if (total <= 1) {
				$('ul.paging.show a.first').hide();
				$('ul.paging.show a.previous').hide();
				$('ul.paging.show a.last').hide();
				$('ul.paging.show a.next').hide();
			} else {
                $('ul.paging.show a.first').show();
                $('ul.paging.show a.previous').show();
                $('ul.paging.show a.last').show();
                $('ul.paging.show a.next').show();
			}
			// End Mantis 994
		});

		$('#Competition').change(function(){
	 		top.location = $('#Competition').val();
		});
		$('#Period').change(function(){
			$('#Leaderboard div.board').removeClass('show');
			var el = $(this).find('option:selected').val();
			$('#Leaderboard div.' + el).addClass('show');
			$('#Leaderboard .show li:first').addClass('first');
			SetTotal();

			$('#Sidebar div.boxer').removeClass('show');
			// Display same div for this/last months prizes
			if (el.match('(this|last)month')) el = 'thismonth';
			$('#Sidebar div.' + el).addClass('show');
			// MN Changes to remove paging panel when there are 
			// not ldrbrd results
			$('ul.paging').removeClass('show');
			var el = $(this).find('option:selected').val();
			var num = $('#Leaderboard div.board.show tr').length;
			if (num > 2) {
				$('ul.paging.' + el).addClass('show');
			}
			// END MN Changes

			// remove paging hrefs if not needed
			$('ul.paging.show a').each(function (e){
				var total = $(this).parent().siblings('li.page').find('span.total').text();
				// always remove the first/prev. Remove the last/next only if needed
				if ((total == 1) || $(this).hasClass('first') || $(this).hasClass('previous')) $(this).addClass('unclickable');
				// Mantis 994 Hide First/Prev/Next/Last if only 1 page of results
	            if (total <= 1) {
    	            $('ul.paging.show a.first').hide();
        	        $('ul.paging.show a.previous').hide();
            	    $('ul.paging.show a.last').hide();
                	$('ul.paging.show a.next').hide();
	            } else {
    	            $('ul.paging.show a.first').show();
        	        $('ul.paging.show a.previous').show();
            	    $('ul.paging.show a.last').show();
                	$('ul.paging.show a.next').show();
	            }
				// End Mantis 994
			});
			$('ul.paging.show span.current').text(1);
			
		});

		$('ul.paging a').click(function(e){
			e.preventDefault();
			$(this).blur();
			
			var first = $('#Leaderboard .show li:first').index();
			var last = $('#Leaderboard .show li:last').index();
			
			var li = $('#Leaderboard .show li:visible');
			var current = ($(li).index());
			
			var skip = false;
			if ((current == first && ($(this).hasClass('first') || $(this).hasClass('previous'))) || (current == last && ($(this).hasClass('next') || $(this).hasClass('last')))){
				skip = true;
			}
			
			if (!skip){
				$(li).hide();
				if ($(this).hasClass('first')){
					$('#Leaderboard .show li:first').show();
				} else if ($(this).hasClass('previous')){
					$(li).prev().show();
				} else if ($(this).hasClass('next')){
					$(li).next().show();
				} else if ($(this).hasClass('last')){
					$('#Leaderboard .show li:last').show();
				}
			}
			updatePaging();
		});

		$('#Leaderboard a.showUserPosition').click(function(e){
			e.preventDefault();
			var skips = $('#Leaderboard .show .skips').val()*1;
			if( $('ul.paging.show span.current').text() == (skips+1) ) {return;}
			for (i=0; i<skips; i++) {
				li = $('#Leaderboard .show li:visible');
				$(li).hide();$(li).next().show();
				$('ul.paging.show span.current').text(  ($('ul.paging.show span.current').text())*1+1  );
			}
			updatePaging();
		});
		
	}

	function updatePaging() {
		var current = ($('#Leaderboard .show li:visible').index() + 1);
		$('ul.paging span.current').text(current);

		if (current == 1) {
			$('ul.paging.show a.first')   .addClass('unclickable');
			$('ul.paging.show a.previous').addClass('unclickable');
		} else {
			$('ul.paging.show a.first')   .removeClass('unclickable');
			$('ul.paging.show a.previous').removeClass('unclickable');
		}

		if(current == $('ul.paging.show span.total').text() ){
			$('ul.paging.show a.last').addClass('unclickable');
			$('ul.paging.show a.next').addClass('unclickable');
		} else {
			$('ul.paging.show a.last').removeClass('unclickable');
			$('ul.paging.show a.next').removeClass('unclickable');
		}
	}
	
	/* Selected Games */
	/* Selected Games */
	var sHandle = 0;
	var sRunning = true;
	function startSelectedGamesCarousel(el){
		var sTimer = 100;
		var sStep = 50;
		var sCounter = 0;

		var controls = $(el).parents('li').find('.controls');
		var next_step = 1;
		var total_steps = $(el).attr('class').replace('c', '');
		var step_height = ($(el).find('li:first').outerHeight() * 2);
		var steps = [];
		for (var i = 0; i < total_steps; i++){
			steps[i] = -(step_height * i);
		}
		
		var slide = function(step){
			$(el).animate({'top' : steps[step - 1]}, 'fast');
			var li = $(controls).find('a.c' + step);
			if ($(li).length > 0){
				$(controls).find('a.c').removeClass('active');
				$(li).addClass('active');
			}
			sCounter = 0;
		};
		
		var autoslide = function(){
			if (sRunning){
				sCounter++;
				if (sCounter == sTimer){
					next_step++;
					if (next_step > total_steps || next_step < 1){
						next_step = 1;
					}
					slide(next_step);
				}
			}
		};
		
		var clickslide = function(step){
			next_step = step;
			slide(next_step);
		};
		
		$(el).hover(function(){
			sRunning = false;
		},function(){
			sRunning = true;
		});
		
		$('#SelectedGames div.controls a').click(function(e){
			e.preventDefault();
			$(this).blur();
			clickslide($(this).text());
		});
		
		sHandle = setInterval(autoslide, sStep);
	}
	function stopSelectedGamesCarousel(){
		clearInterval(sHandle);
		$('#SelectedGames div.carousel ul').each(function(){
			$(this).css('top', '0px');
		});
		$('#SelectedGames div.controls a.c').removeClass('active');
		$('#SelectedGames div.controls').each(function(){
			$(this).find('a:first').addClass('active');
		});
	}
	if ($('#SelectedGames').length > 0){
		var playMe = false;
		$('#SelectedGames div.carousel ul').each(function(){
			var lis = $(this).find('li').length;
			var count = Math.ceil(lis / 2);
			if (count != (lis / 2)){
				$(this).append('<li class="empty"></li>');
			}
			$(this).addClass('c' + count);
			for (var i = 0; i < count; i++){
				$(this).parents('li').find('.controls').append('<a class="c c' + (i + 1) + '" href="#"><b>' + (i + 1) + '</b></a>');
			}
			$(this).parents('li').find('.controls a:first').addClass('active');
			if ($(this).parents('li').hasClass('open')){
				playMe = $(this);
			}
		});
		
		startSelectedGamesCarousel(playMe);
	}
	$("#SelectedGames span").click(function(e) {
		e.preventDefault();
		$(this).blur();
		
		if (!$(this).parent('li').hasClass("open")){
			stopSelectedGamesCarousel();
			
			$(this).parents('ul').find('div').slideUp('fast');
			$(this).parents('ul').find('li').removeClass("open");
			$(this).parent('li').addClass("open").find('div').slideDown('fast');
			
			startSelectedGamesCarousel($(this).parent('li').find('ul'));
		}
	});
	
	/* Latest Winners */
	$('#LatestWinnersTable select').change(function(){
		$('#LatestWinnersTable table').removeClass('show');
		var el = $(this).find('option:selected').val();
		$('#LatestWinnersTable table.' + el).addClass('show');
	});
	if ($('#Winners').length > 0){
		$("#Winners .carousel li a").each(function(){
			var bg = $(this).find('b').html().replace(/\s+/g, '-').replace(/\'/g, '').toLowerCase();
			$(this).css('background-image', 'url('+SA_GIF_URL+'/winners/small/' + bg + '.jpg)');
		});
		var wTimer = 200;
		var wStep = 200;
		var wRunning = true;
		var wCounter = 0;
		var wHandle = 0;
		var doubleWin = function(){
			if (wRunning){
				wCounter++;
				if (wCounter == wTimer){
					clearInterval(wHandle);
					wCounter = 0;
					carousel.next();
				}
			}
		};
		$("#Winners .carousel").hover(function(){
			wRunning = false;
		}, function() {
			wRunning = true;
		});
		function winners_initCallback(carousel, state){
			$('#Winners div.carousel li').each(function(index){
				$(this).find('a').prepend('<b>' + index + '</b>');
			});
			$('#Winners div.carousel a').click(function(e) {
				e.preventDefault();
				clearInterval(wHandle);

				if ($(this).hasClass('previous')){
					carousel.prev();
				} else if ($(this).hasClass('next')) {
					carousel.next();
				} else {
					carousel.scroll($.jcarousel.intval($(this).find('b').text()) + 1);
				}
			});
			wCounter = 0;
			wHandle = setInterval(doubleWin, wStep);
		}
		function winners_itemVisibleInCallback(carousel, item, i, state){
			wCounter = 0;
			wHandle = setInterval(doubleWin, wStep);

			var name = $(item).find('.caption b').html().replace(/\s+/g, '-').replace(/\'/g, '').toLowerCase();
			$('#Winners h3').text($(item).find('.header').text());
			$('#Winners blockquote p').text($(item).find('.quote').text());
			$('#Winners div.polaroid img').attr('src', SA_GIF_URL+'/winners/large/' + name + '.jpg');
			$('#Winners div.polaroid span').html($(item).find('.caption').html());
		}
		$('#Winners div.carousel ul').jcarousel({
			scroll: 1,
			wrap: 'circular',
			buttonNextHTML: null,
			buttonPrevHTML: null,
			initCallback: winners_initCallback,
			itemFirstInCallback: winners_itemVisibleInCallback
		});
		var carousel = jQuery('#Winners div.carousel ul').data('jcarousel');
	}
	if ($('#LatestWinners').length > 0){
		var timerLatestWinners = false;
		var startLatestWinners = function(el){
			var lwSpeed = 3000;
			var lwHeight = $(el).find('li:first').outerHeight();
			var lwSlide = function(){
				$(el).animate({'top' : -lwHeight}, 'slow', function(){
					if ($(el).children().size() > 1) {
						$(el).find('li:last').after($(el).find('li:first'));
					}
					$(el).css({'top' : '0px'});
				});
			};
			
			timerLatestWinners = setInterval(lwSlide, lwSpeed);
			
			$(el).hover(function(){
				clearInterval(timerLatestWinners);
			},function(){
				timerLatestWinners = setInterval(lwSlide, lwSpeed);
			});
		};
		startLatestWinners('#LatestWinners ul');
	}

	/* Main Cross Fader Banner */
	if ($('#CrossFader').length > 0){
		var cTimer = 100;
		var cStep = 50;
		var cRunning = true;
		var cCounter = 0;
		var cHandle = 0;
		var doubleCross = function(){
			if (cRunning){
				$("#CrossFader .controls .load").reportprogress(++cCounter);
				if (cCounter == cTimer){
					clearInterval(cHandle);
					cCounter = 0;
					$('#CrossFader ul').cycle('next');
				}
			}
		};
		var cross_before = function(){
			$("#CrossFader div.controls i").css("width", "0");
			cCounter = 0;
			cHandle = setInterval(doubleCross, cStep);
		};
		var cross_controls = function(idx, slide) {
			return '<a href="#"><i></i><b>' + (idx + 1) + '</b></a>';
		};
		var cross_click = function(){
			clearInterval(cHandle);
		};
		$("#CrossFader").hover(function(){
			cRunning = false;
		}, function() {
			cRunning = true;
		});
		$('#CrossFader ul').after('<div class="controls">').cycle({
			timeout: 0,
		    pager:  '#CrossFader div.controls',
		    activePagerClass: 'load',
		    pagerAnchorBuilder: cross_controls,
		    pagerClick: cross_click,
		   	before: cross_before
		});
	}


	
	/* Available to Play Now */
	if ($('#PlayNow').length > 0){
		$("#PlayNow ul.carousel strong").each(function(){
			var bg = $(this).html().replace(/\s+/g, '-').replace(/\'/g, '').toLowerCase();
			$(this).parent("a").css('background-image', 'url('+SA_GIF_URL+'/hp_games/' + bg + '.jpg)');
		});
		var count = Math.ceil($('#PlayNow ul.carousel li').length / 4);
		for (i = 0; i < count; i++){
			var y = i * 4 + 1;
			$('#PlayNow ul.controls li.next').before('<li class="c c' + y + '"><a href="#">' + y + '</a></li>');
		}
		function playnow_initCallback(carousel, state){
			$('#PlayNow ul.controls a').click(function(e) {
				e.preventDefault();
				
				if ($(this).parent('li').hasClass('previous')){
					carousel.prev();
				} else if ($(this).parent('li').hasClass('next')) {
					carousel.next();
				} else {
					carousel.scroll($.jcarousel.intval($(this).text()));
				}
			});
			
			carousel.clip.hover(function() {
				carousel.stopAuto();
			}, function() {
				carousel.startAuto();
			});
		}
		function playnow_itemVisibleInCallback(carousel, item, i, state, evt){
			var li = '#PlayNow ul.controls li.c' + i;
			if ($(li).length > 0){
				$('#PlayNow ul.controls li.c').removeClass('active');
				$(li).addClass('active');
			}
		}
	    $('#PlayNow ul.carousel').jcarousel({
	        scroll: 4,
	        wrap: 'both',
	    	buttonNextHTML: null,
	    	buttonPrevHTML: null,
	        initCallback: playnow_initCallback,
	        itemVisibleInCallback: playnow_itemVisibleInCallback
	    });
	}
	
	/* Swap Banners */
	if ($("#SelectedGames").length > 0){
		$("#SelectedGames div.carousel span").each(function(){
			var bg = $(this).html().replace(/\s+/g, '-').replace(/\'/g, '').toLowerCase();
// 			$(this).parent("a").find('em').css('background-image', 'url('+SA_GIF_URL+'/instantwins/64x52/' + bg + '.jpg)');
		});
	}
	if ($("div.swapbanner").length > 0){
		$("div.swapbanner h1").each(function(){
			var bg = $(this).html().replace(/\s+/g, '-').replace(/\'/g, '').toLowerCase();
			// SA_GIF_URL is handed from the template player elsewhere
			$(this).parent("div.swapbanner").css('background-image', 'url('+SA_GIF_URL+'/banner_headers/swap_' + bg + '.jpg)');
		});
	}
	if ($("div.categories dl").length > 0){
		$("div.categories dd a").each(function(){
			var bg = $(this).html().replace(/<(B|b)[^>]*>[^<]*(<\/B>|<\/b>)/ig,"").replace(/\s+/g, '-').replace(/\'/g, '').toLowerCase();
	//		$(this).find("b").css('background-image', 'url('+SA_GIF_URL+'/instantwins/110x90/' + bg + '.jpg)');
		});
	}
	if ($("body.instantwins ul.games li.game").length > 0){
		$("body.instantwins ul.games li.game h3").each(function(){
			var bg = $(this).html().replace(/\s+/g, '-').replace(/\'/g, '').toLowerCase();
	//		$(this).parent('.game').find(".header").css('background-image', 'url('+SA_GIF_URL+'/instantwins/180x90/' + bg + '.jpg)');
		});
	}
	if ($("body.lotteries ul.games li.game").length > 0){
		$("body.lotteries ul.games li.game h3").each(function(){
			var bg = $(this).html().replace(/\s+/g, '-').replace(/\'/g, '').toLowerCase();
			$(this).parent('.game').find(".header").css('background-image', 'url('+SA_GIF_URL+'/lotteries/' + bg + '.jpg)');
		});
	}


	$('ul.result div.header a').click(function(e){
		// Depricated function kept for reference.
		return;
		// Do an ajax call to get the result
		if ($(this).attr('href')){
			eval($(this).attr('href').split('javascript:')[1]);
		}

		e.preventDefault();
		$(this).blur();
	
		var skip = false;
		if (($(this).parents('li:first-child').length > 0 && $(this).hasClass('next')) || ($(this).parents('li:last-child').length > 0 && $(this).hasClass('previous'))){
			skip = true;
		}

		if (!skip){
			$(this).parent('li').hide();
			if ($(this).hasClass('next')){
				$(this).parent('li').prev().show();
			} else {
				$(this).parent('li').next().show();
			}
		}
	});
	$('div.promotionTable div.header a').click(function(e){
		e.preventDefault();
		$(this).blur();
		
		$(this).parents('div.promotionTable').find('table').toggle('fast');
		$(this).parents('div.promotionTable').toggleClass('open');
		$(this).text($(this).text() == 'Show Details' ? 'Hide Details' : 'Show Details');
	});
	$('body.promotions #Body div.promotion div.section h3 b').click(function(){
		//$(this).parents('.section').find('ul').toggle('fast');
		//$(this).parents('.section').toggleClass('closed');
	});
	$('a.switch').click(function(e) {
		e.preventDefault();
		
		var el = '#' + $(this).attr('name');
		
		$(this).parents('a.switch').hide();
		$(el).show();
	});
	$("#TreeView span").click(function(e) {
		e.preventDefault();
		$(this).blur();
		
		if ($(this).parent("li").hasClass("open") || $(this).parent("li").hasClass("expanded")) {
			$(this).parent('li').find('ul:first').slideUp('fast');
			$(this).parent('li').removeClass("open").removeClass("expanded");
		} else {
			$(this).parent('li').addClass("expanded").find('ul:first').slideDown('fast');
		}
	});

}

function initValidation(){
	var LoginForm = document.getElementById('Login');
	if (LoginForm){
		$("#Login").validate({
			rules: {
				username: {
					required: true,
					rangelength: [2, 20]
				},
				pwd: {
					required: true,
					rangelength: [2, 20]
				}
			},
			messages: {
				username: "",
				pwd: ""
			}
		});
	}
}


/*
 * Copyright (c) 2007 Josh Bush (digitalbush.com)
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:

 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE. 
 */
 
/*
 * Progress Bar Plugin for jQuery
 * Version: Alpha 2
 * Release: 2007-02-26
 */ 
(function($) {	
	//Main Method
	$.fn.reportprogress = function(val,maxVal) {			
		var max=100;
		if(maxVal)
			max=maxVal;
		return this.each(
			function(){		
				var div=$(this);
				var innerdiv=div.find("i");
				var width=Math.round(val/max*100);
				innerdiv.css("width",width+"%");	
			}
		);
	};
})(jQuery);





// Do a call to check if the login cookie is valid
doCookieCheck = function () {
	var url = "?action=GoVerifyLogin";
	var r = SA_singleton_request_broker.instance();
	r.send( {
			'priority': 0,
			'method' : 'GET',
			'url' : url,
			'callback': cookieCheckCallback,
			'debug' : true
		} ); 
}

cookieCheckCallback = function (response) {
	var ret_val = response.responseText;
	if (ret_val == "ERR") {
		window.location = "?action=GoAcctHome&login_timeout=1";
	} else {
	}
}

// Do the cookie check once per minute
startCookieCheck = function () {
	setTimeout(function() {
		doCookieCheck();

		setTimeout(arguments.callee, 60000);
	},60000);
}

submitLoginForm = function (source) {
	source.disabled = true;
	source.form.submit();
}

/*
 * $Id: global.js,v 1.1.2.3.2.4 2011-03-08 17:21:24 pmiller Exp $
 * Copyright (c) 2004 Orbis Technology Ltd. All rights reserved.
 */



// trim a string
function str_trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}



// round a float to 2 decimal places
function round_float(n) {

	var s = "" + Math.round(n * 100) / 100
	var i = s.indexOf('.')

	if(i < 0) {
		return s + ".00"
	}

	var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
	if(i + 2 == s.length) {
		t += "0"
	}

	return t;
}



// open a window
function open_window(url, name, width, height, resizable, scrollbars) {

	var w = window.screen.width;
	var h = window.screen.height;

	if(width > w) {
		width = w / 2;
	}
	if(height > h) {
		heigth = h / 2;
	}

	// spaces in window name cause problems for IE 6-7
	name = name.replace(/ /g,"_");

	var new_window = window.open(url, name,
		"resizable=" + resizable +
		",scrollbars=" + scrollbars +
		",width=" + width +
		",height=" + height +
		",status=yes");
	new_window.focus();
	new_window.opener = window;
}



// get a cookie
function get_cookie(name) {

	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) {
			return null;
		}
	}
	else {
		begin += 2;
	}

	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}

	return unescape(dc.substring(begin + prefix.length, end));
}



// set a cookie
function set_cookie(name, value, expires, path, domain, secure) {

	var curCookie = name + "=" + value +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

	document.cookie = curCookie;
}



// get user-agent
var at = new UserAgent();
function UserAgent() {

	var b = navigator.appName.toUpperCase();

	if(b == "NETSCAPE") {
		this.b = "ns";
	}
	else if(b == "MICROSOFT INTERNET EXPLORER") {
		this.b="ie";
	}
	else if(b == "OPERA") {
		this.b = "op";
	}
	else {
		this.b = b;
	}

	this.version = navigator.appVersion;
	this.v = parseInt(this.version);

	this.ns = (this.b=="ns" && this.v>=4);
	this.ns4 = (this.b=="ns" && this.v==4);
	this.ns5 = (this.b=="ns" && this.v==5);

	this.ie = (this.b=="ie" && this.v>=4);
	this.ie4 = (this.version.indexOf('MSIE 4')>0);
	this.ie5 = (this.version.indexOf('MSIE 5')>0);
	this.ie55 = (this.version.indexOf('MSIE 5.5')>0);
	this.ie6 = (this.version.indexOf('MSIE 6')>0);
	this.ie9 = (this.version.indexOf('MSIE 9')>0);

	this.op = (this.b=="op");
	this.op4 = (this.b=="op" && this.v==4);
	this.op5 = (this.b=="op" && this.v==5);
}



// Add a form variable
function insertInputObj(form, type, id, name, value) {

	var doc = form.ownerDocument;

	if(at.ie && !at.ie9){
		inputObj = doc.createElement("<input name='" + name + "'>");
	} else {
		inputObj      = doc.createElement("input");
		inputObj.name = name;
	}

	inputObj.type  = type;
	inputObj.id    = id;
	inputObj.value = value;

	form.appendChild(inputObj);
}



// Change the display characteristics of a document element
function alterElements(tag, id, visibility) {

	var elements     = document.getElementsByTagName(tag);
	var num_elements = elements.length;

	for(var i = 0; i < num_elements; i++) {
		if(elements.item(i).id == id) {
			elements.item(i).style.display = visibility;
		}
	}
}



// get a currency symbol
function get_ccy_symbol (code) {

	switch(code) {
		case "GBP": { return "\u00A3"; }
		case "EUR": { return "\u20AC"; }
		case "USD": { return "$"; }
		default:    { return code + " "; }
	}
}



// fraction to decimal conversion
function frac_to_dec(num, den) {

	var p = num + "/" + den;

	if(p == "13/8") {
		return 2.62;
	}
	if(p == "15/8") {
		return 2.87;
	}
	if(p == "11/8") {
		return 2.37;
	}
	if(p == "8/13") {
		return 1.61;
	}
	if(p == "2/7") {
		return 1.28;
	}
	if(p == "1/8") {
		return 1.12;
	}

	return (parseFloat(num) / parseFloat(den)) + 1.00;
}

/*
 * Used to link a customer's name in a leaderboard to their community profile.
 */
function gotoProfile (link,acctno) {
	if (acctno=='') return false;
	window.location = link+acctno;
}

/*
 *
 */
function gotoPage (link) {
	window.location = link
}



/*
 * Updates the account balance displayed on the page.
 * Makes an ajax call with the action GoBalanceUpdate.
 * Callback is handled by balanceUpdateCallback.
 */
function updateAccountBalances() {
	// If we're not logged in, the account box won't be there, so no need to
	// update.
	if (document.getElementById("AccountBalances") == null) {
		return;
	}


    url = "?action=GoBalanceUpdate";

    var r = SA_request_broker;
    r.send( {
        'priority': r.UPDATE_BALS,
        'method'  : 'GET',
        'url'     : url,
        'callback': balanceUpdateCallback,
        'debug'   : true
    } );
}



/*
 * Handles the callback from the request made in updateAccountBalances().
 * Inserts the received HTML into the page (uses a DOM fragment) and re-adds
 * the relevant jQuery-based event handlers.
 */
function balanceUpdateCallback(response) {
    printfire(response);
    var fragment  = document.createDocumentFragment();
	var container = document.createElement('div');

	// Strip out any unwanted whitespace, so we only have the <table> as a childNode
    container.innerHTML = str_trim(response.responseText);
	var newTable = container.childNodes[0];

    var oldTable = document.getElementById("AccountBalances");
	var parentDiv= oldTable.parentNode;
	// Make sure that the new table is displayed if the old one was
	if ($("a.open", parentDiv).length > 0) {
		$("a", newTable).toggleClass('open');
		$("table", newTable).css("display", "inline-block");
		$("a",newTable).text('Hide Balances');
	}
    parentDiv.parentNode.replaceChild(newTable, parentDiv);
	$("a", newTable).click(function(e) {
			$(this).parent("div").find("table").toggle();
			$(this).text($(this).text() == 'Show Balances' ? 'Hide Balances' : 'Show Balances');
			$(this).toggleClass('open');
			}); 
}



/*
 * $Id: login.js,v 1.1.4.2.2.1 2010-06-24 14:36:54 anybakk Exp $
 * Copyright (c) 2008 Orbis Technology Ltd. All rights reserved.
 */

// this is to stop login submit being call twice (which appears to happen when button is clicked)
var LoginSubmitted = false;

// Variable to store the function we want to call before login. Basically the first reason why
// it has been added is to save game selections before login to avoid loosing all the selection
// when a customer forgot to login before starting playing a game.
var pre_login_function = "";

// on pressing any key within the login password field
function login_on_enter(e) {
	// on pressing enter within the login password field e.which or e.keyCode = 13
	if(e && e.which) {
		if(e.which == 13) {
			go_login();
		}
	}
	else {
		if(e && e.keyCode == 13) {
			go_login();
		}
	}
}


// Login
function go_login() {

	if (!LoginSubmitted) {
		var f = document.forms['Login'];
		var n_errs = 0;

		reset_error();

		n_errs += ck_mandatory(f.username.value, getXlation("NAV_USERNAME"),
				1, 16, true);
		n_errs += ck_mandatory(f.pwd.value, getXlation("NAV_PASSWORD"), 1, 16,
				true);

		if(n_errs > 0) {
			alert(error_list);
		} else {
			// Lock the login
			LoginSubmitted = true;
			
			// Perform the pre-login action if defined
			if(pre_login_function != "") {eval(pre_login_function);}

			// Do the Login
			submit_form('Login','GoLogin', 'post');
		}
	}
}
/*
 * $Id: menu.js,v 1.1.4.2 2010-05-10 13:06:27 jcheese Exp $
 * Copyright (c) 2004 Orbis Technology Ltd. All rights reserved.
 */

// timer
var timeOn  = null;
var timeOn2 = null;

// maximum number of menus
var numMenus = 50;

// count the menus defined so far
var currentMenuNo = 0;

// menu state
var menuActive = new Array(numMenus);

// menu tier
var tier = new Array(numMenus);

// line-up menus
var borderMod = new Array(numMenus);

// off class of the corresponding (sub)menu label link
var offClass = new Array(numMenus);

// on class of the corresponding (sub)menu label link
var onClass = new Array(numMenus);

// off colour of the corresponding (sub)menu label background
var offColours = new Array(numMenus);

// on colour of the corresponding (sub)menu label background
var onColours = new Array(numMenus);

// name of the bullet object (if any) used by the corresponding (sub)menu label
var labelBulletName = new Array(numMenus);

// the type of (sub)menu label corresponding to this menu
var menuType = new Array(numMenus);

// hold the menu objects in the system
var menus = new Array(numMenus);

// location of shim.gif
var shimGIF = "shim.gif"


// sniff out problem browsers
var browser = new SniffBrowser();
function SniffBrowser() {

	var ns4 = document.layers;
	var op5 = navigator.userAgent.indexOf("Opera 5") !=-1 || navigator.userAgent.indexOf("Opera/5") != -1;
	var op6 = navigator.userAgent.indexOf("Opera 6") !=-1 || navigator.userAgent.indexOf("Opera/6") != -1;
	var agt = navigator.userAgent.toLowerCase();
	var mac = agt.indexOf("mac") != -1;
	var ie  = agt.indexOf("msie") != -1;
	var mac_ie = mac && ie;
}


// get the style object for the different types of browsers
function getStyleObject(objectId, doc) {

	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	}
	else if(document.all && document.all(objectId)) {
		return document.all(objectId).style;
	}
	else if(document.layers && document.layers[objectId]) {
		return getObjNN4(document, objectId);
	}

	return false;
}


// hide or show a page element
function changeObjectVisibility(objectId, newVisibility) {

	var styleObject = getStyleObject(objectId, document);
	if(styleObject) {
		styleObject.visibility = newVisibility;
		return true;
	}

	return false;
}


// find an image (NS4 only)
function findImage(name, doc) {

	var i, img;

	for(i = 0; i < doc.images.length; i++) {
		if(doc.images[i].name == name) {
			return doc.images[i];
		}
	}
	for(i = 0; i < doc.layers.length; i++) {
		if((img = findImage(name, doc.layers[i].document)) != null) {
			img.container = doc.layers[i];
			return img;
		}
	}

	return null;
}


// get an image (NS4 only)
function getImage(name) {

	if (document.layers) {
		return findImage(name, document);
	}
	return null;
}


// find an object (NS4 only)
function getObjNN4(obj, name)
{
	var x = obj.layers;
	var foundLayer;

	for(var i=0; i < x.length; i++) {
		if(x[i].id == name) {
		 	foundLayer = x[i];
		}
		else if(x[i].layers.length) {
			var tmp = getObjNN4(x[i], name);
		}
		if(tmp) {
			foundLayer = tmp;
		}
	}

	return foundLayer;
}


// get an element's height
function getElementHeight(Elem) {

	var elem, xPos;

	if(browser.ns4) {
		elem = getObjNN4(document, Elem);
		return elem.clip.height;
	}

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	} else if (document.all) {
		elem = document.all[Elem];
	}

	if(browser.op5) {
		xPos = elem.style.pixelHeight;
	} else {
		xPos = elem.offsetHeight;
	}

	return xPos;
}


// get an element's width
function getElementWidth(Elem) {

	var elem, xPos;

	if(browser.ns4) {
		elem = getObjNN4(document, Elem);
		return elem.clip.width;
	}

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	} else if(document.all) {
		elem = document.all[Elem];
	}

	if(browser.op5) {
		xPos = elem.style.pixelWidth;
	}
	else {
		xPos = elem.offsetWidth;
	}

	return xPos;
}


// get the X co-ordinate of an element
function getElementLeft(Elem) {

	var elem, xPos, tempEl;

	if(browser.ns4) {
		elem = getObjNN4(document, Elem);
		return elem.pageX;
	}

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	} else if (document.all){
		elem = document.all[Elem];
	}
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while(tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}

	return xPos;
}



// get the Y co-ordinate of an element
function getElementTop(Elem) {

	var elem, yPos, tempEl;

	if(browser.ns4) {
		elem = getObjNN4(document, Elem);
		return elem.pageY;
	}

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	} else if (document.all) {
		elem = document.all[Elem];
	}
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while(tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}


// get the X co-ordinate of an image
function getImageLeft(img) {

	if(document.layers) {
		var m = getImage(img);
		if(m.container != null) {
			return m.container.pageX + m.x;
		}
		return m.x;
	}

	return getElementLeft(img);
}


// get the Y co-ordinate of an image
function getImageTop(img) {

	if(document.layers) {
		var m = getImage(img);
		if(m.container != img) {
			return m.container.pageY + m.y;
		}
		return m.y;
	}

	return getElementTop(img);
}


// get image width
function getImageWidth(img) {

	if(document.layers) {
		var m = getImage(img);
		return m.width;
	}

	return getElementWidth(img);
}


// get image height
function getImageHeight(img) {

	if(document.layers) {
		var m = getImage(img);
		return m.height;
	}

	return getElementHeight(img);
}


// move an element to a new set of X + Y co-ordinates
function moveXY(Obj, x, y) {

	var obj = getStyleObject(Obj)

	if(browser.ns4) {
		obj.top = y;
		obj.left = x;
	}
	else if(browser.op5) {
		obj.pixelTop = y;
		obj.pixelLeft = x;
	}
	else {
		obj.top = y + 'px';
		obj.left = x + 'px';
	}
}


// change style class of an element
function changeClass(Elem, Class) {

	var elem;

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	}
	else if(document.all){
		elem = document.all[Elem];
	}
	if(browser.op5 || browser.op6) {
		elem.style.className = Class;
	}
	else {
		elem.className = Class;
	}
}


// change the background of an element
function changeBGColour(Object, colour) {

	if(browser.ns4) {
		var obj = getObjNN4(document, Object);
		obj.bgColor=colour;
	} else {
		var obj = getStyleObject(Object);
		if(browser.op5) {
			obj.background = colour;
		} else {
			obj.backgroundColor = colour;
		}
	}
}


// changes the source the source of "target" to "source"
function changeImage(target, source) {

	var imageObj;

	if(browser.ns4) {
		imageObj = getImage(target);
		if(imageObj) {
			imageObj.src = eval(source).src;
		}
	} else {
		imageObj = eval('document.images.' + target);
		if (imageObj) {
			imageObj.src = eval(source).src;
		}
	}
}


// Writes a 1 pixel wide td element with a background colour "B".
function borderCell(B) {

	return '<td width="1" bgcolor="' + B + '">' +
	    '<img src="' + shimGIF + '" width="1" height="1" border="0"></td>';
}


/* Writes a table row 1 pixel high, containing a td element with background
 * colour "B" and a colspan of "C"
 */
function borderRow(B, C) {

	return '<tr><td height="1" colspan="' + C + '" bgcolor="' + B + '">' +
	   '<img src="' + shimGIF + '" width="1" height="1" border="0"></td></tr>';
}



// clear the timeout when a mouse enters a menu item or label, created on menuOut
function menuOver() {
	clearTimeout(timeOn);
}


// hide all the menus after 1 second, when a mouse leaves a menu item or label
function menuOut() {
	clearTimeout(timeOn2);
	timeOn = setTimeout("hideAllMenus()", 500);
}


// show a menu
function showMenu(m_No, eventObj) {

	// hide all the other menus
	hideAllMenusTier(tier[m_No] - 1);


	var borderModSize = borderMod[m_No];

	// change the bg colour + class
	if(browser.ns4) {
		changeBGColour('menuLabel' + m_No, onColours[m_No]);
	}
	else {
		changeBGColour('labelCell' + m_No, onColours[m_No]);
		changeClass('menuLink' + m_No, onClass[m_No]);
	}

	// if the Menu Label has a bullet point then change it
	if(labelBulletName[m_No] != null){
		changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.onImage');
	}

	// set the menu as "active"
	menuActive[m_No] = true;

	// if it's not a blank menu...
	if(menuType[m_No] != 'blank') {

		// ID of the Menus Label
		if(browser.ns4) {
			labelObj = 'menuLabel' + m_No;
		}
		else {
			labelObj = 'labelCell' + m_No;
		}

		// X + Y co-ordinates of the menu label
		var x = getElementLeft(labelObj) - borderModSize;
		var y = getElementTop(labelObj) + getElementHeight(labelObj);

		// for centered menus...
		if (menus[m_No].align == 'center') {
			x = x + ((getElementWidth(labelObj) - getElementWidth('menu' + m_No)) / 2);
		}

		// right aligned menus
		if (menus[m_No].align == 'right') {
			x = x + ((getElementWidth(labelObj) - getElementWidth('menu' + m_No))) + (borderModSize * 2);
		}

		// move the menu to it's rightful place
		moveXY('menu' + m_No, x, y);

		// and finally show the menu
		return changeObjectVisibility('menu' + m_No, 'visible');
	}
}


// displays side menus (with a slight delay)
function showMenuSide(m_No, eventObj, Tier) {

	timeOn2 = setTimeout('_showMenuSide("' + m_No + '","' + eventObj + '","' + Tier + '")', 150);
}


// displays side menus
function _showMenuSide(m_No, eventObj, Tier) {

	// hide all the other menus
	hideAllMenusTier(tier[m_No]-1);

	var borderModSize = borderMod[m_No];

	// bg colour + class
	if(browser.ns4) {
		changeBGColour('menuLabel' + m_No, onColours[m_No]);
	} else {
		changeBGColour('labelCell' + m_No, onColours[m_No]);
		changeClass('menuLink' + m_No, onClass[m_No]);
	}

	// if the Menu Label has a bullet point then change it
	if (labelBulletName[m_No] != null) {
		changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.onImage');
	}

	// active
	menuActive[m_No] = true;

	// if it's not a blank menu...
	if(menuType[m_No] != 'blank') {
		if(browser.ns4) {
			labelObj = 'menuLabel' + m_No;
		}
		else {
			labelObj = 'labelCell' + m_No;
			if(browser.mac_ie) {
				labelObj = 'labelRow' + m_No;
			}
		}

		/* X + Y
		 * - offset X by 3 pixels, so we can have overlapping menus
		 * - offset Y by half the height of the label, so we can overlap
		 */
		x = getElementLeft(labelObj) - 3;
		y = getElementTop(labelObj) - borderModSize + (getElementHeight(labelObj) / 2);

		// right aligned menus
		if(menus[m_No].align=='right') {
			x = x + getElementWidth(labelObj);
		}
		else {
			x = x - getElementWidth('menu' + m_No);
		}

		// move the menu to it's correct placement...
		moveXY('menu' + m_No, x, y);

		// display
		return changeObjectVisibility('menu' + m_No, 'visible');
	}
}



// hide all menus
function hideAllMenus() {

	for(var i = 1; i < (currentMenuNo + 1); i++) {
		if(menuActive[i]) {
			hideMenu(i);
		}
	}
}


// hide all menus on a tier
function hideAllMenusTier(Tier) {

	for(var i = 1; i < (currentMenuNo + 1); i++) {
		if(tier[i] > Tier && menuActive[i]) {
			hideMenu(i);
		}
	}
}


// hide a menu
function hideMenu(m_No) {

	if(browser.ns4) {
		changeBGColour('menuLabel' + m_No, offColours[m_No]);
	}
	else {
		changeBGColour('labelCell' + m_No, offColours[m_No]);
		changeClass('menuLink' + m_No, offClass[m_No]);
	}

	if(labelBulletName[m_No] != null){
		changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.offImage');
	}
	menuActive[m_No] = false;

	return changeObjectVisibility('menu' + m_No, 'hidden');
}



/* menu-bar object
 *
 *   barName      - menu bar div id
 *   barWidth     - width of the menu-bar (pixels)
 *   orientation  - horizontal or vertical
 *   iBor         - inner border colour
 *   oBor         - outer border colour
 */
function MenuBar(barName, barWidth, orientation, iBor, oBor) {

	// count the number of labels in the menu bar
	this.numLabels = 0;

	// border colours + orientation
	this.iBor = iBor;
	this.oBor = oBor;
	this.orientation = orientation;

	// default height
	this.height = 15;

	// label text (menu HTML)
	this.labelText = new Array();

	// veritical menu bars
	this.rowText = new Array();

	// link classes
	this.offClass = 'JSMenuLabelLink';
	this.onClass = 'JSMenuLabelLinkOn';

	// bullet point alignment (left | right)
	this.bulletAlign = 'left';

	// target type (self | iframe | frame | new)
	this.targetType = 'self';

	// target frame ( _self | _blank | (i)frame name)
	this.targetFrame = '_self';


	/* add a lebel
	 *
	 *   bullet       - name of bullet, or null
	 *   labelText    - text to appear in the menu-label
	 *   menuNo       - menu number
	 *   labelWidth   - label width (pixels)
	 *   offColour    - background colour of the label's off state
	 *   onColour     - background colour of the label's on state
	 *   labelURL     - menu link URL
	 *   align        - text alignment
	 */
	this.add = function(bullet, labelText, menuNo, labelWidth, offColour, onColour, labelURL, align) {

		this.numLabels += 1;

		// set the tier for the menu hanging from this label
		tier[menuNo] = 0;

		// offset for placing the menu due to the outer border
		if(this.oBor != null) {
			borderMod[menuNo] = 1;
		}
		else {
			borderMod[menuNo] = 0;
		}

		// set the globals for the menu label
		if(menuNo != null) {
			onColours[menuNo]       = onColour;
			offColours[menuNo]      = offColour;
			onClass[menuNo]         = this.onClass;
			offClass[menuNo]        = this.offClass;
			labelBulletName[menuNo] = bullet;
		}

		// temporary string object to hold the html for the menu label
		var temp = new String('');

		// string object to hold the row tag for the label (if necessary)
		this.rowText[this.numLabels] = new String('');

		// td tag
		temp += '<td id="labelCell' + menuNo + '" width="' + labelWidth +
		    '" bgcolor="' + offColour + '" valign="middle" height="' + this.height + '" ';

		// non NS4
		if(!browser.ns4) {
			temp += ' onmouseout="menuOut(); "onmouseover="menuOver(); ';
			if(this.orientation == 'vertical') {
				temp += 'return !showMenuSide(' + menuNo + ', event, tier[' + menuNo + ']);" ';
			}
			else {
				temp += 'return !showMenu(' + menuNo + ', event);" ';
			}
		}
		temp +='>';

		// NS4
		if(browser.ns4) {
			temp +='<ilayer><layer onmouseout="menuOut();" onmouseover="menuOver(); ';
			if(this.orientation == 'vertical') {
				temp +='return !showMenuSide(' + menuNo + ', event, tier[' + menuNo + ']);" ';
			}
			else {
				temp +='return !showMenu(' + menuNo + ', event);" ';
			}

		// create the div on non NS4 browsers
		} else {
			temp +='<div ';
		}

		// give the layer/div an ID and start the link tag
		temp += ' class="JSMenuLabel' + align + '" width="' + labelWidth + '" id="menuLabel' + menuNo +'">' +
		    '<a href="' + labelURL + '" target="'+ this.targetFrame + '" class="' + this.offClass + '" id="menuLink' + menuNo +'">';

		// bullet point enabled
		if(bullet != null) {
			temp += '<img src="' + eval(bullet + ".URL") +
			    '" border="0" align="' + this.bulletAlign +
			    '" id="menuBullet' + menuNo + '" name="menuBullet' + menuNo +
			    '">';
		}

		// close the link tag
		temp += labelText + '</a>';

		// close the div or layer
		if(browser.ns4) {
			temp += '</layer></ilayer>';
		}
		else {
			temp += '</div>';
		}

		// close the td tag
		temp += '</td>';

		// store the HTML
		this.labelText[this.numLabels] = new String(temp);
	}


	// write the menu-bar
	this.write = function() {

		var oBor = this.oBor;
		var iBor = this.iBor;

		// a div tag for the menu bar so we can position it using CSS
		var menuBarStr = new String();
		menuBarStr += '<div id="' + barName + '"><table border="0" cellpadding="0" cellspacing="0">';

		// side menu
		if (this.orientation == 'vertical') {
			if(oBor != null) {
				menuBarStr += borderRow(oBor, 3);
			}
			for(var count = 0; count < this.numLabels; count++) {
				menuBarStr += this.rowText[count+1];
				if(oBor != null) {
					menuBarStr += borderCell(oBor);
				}
				menuBarStr += this.labelText[count+1];
				if(oBor != null) {
					menuBarStr += borderCell(oBor);
				}
				menuBarStr += '</tr>';
				if(iBor != null && count < (this.numLabels - 1)) {
					if(oBor != null) {
						menuBarStr += '<tr>' + borderCell(oBor) + borderCell(iBor) + borderCell(oBor) + '</tr>';
					}
					else {
						menuBarStr += borderRow(iBor, 1);
					}
				}
			}
			if (oBor != null) {
				menuBarStr += borderRow(oBor, 3);
			}

		// bar menu
		} else {
			if(oBor != null) {
				if(iBor != null) {
					menuBarStr += borderRow(oBor, ((this.numLabels * 2) + 1));
				}
				else {
					menuBarStr += borderRow(oBor, (this.numLabels + 2));
				}
			}
			menuBarStr += '<tr>';
			if(oBor != null) {
				menuBarStr += borderCell(oBor);
			}

			// add the labels
			for(var count = 0; count < this.numLabels; count++) {
				menuBarStr += this.rowText[count + 1];
				menuBarStr += this.labelText[count + 1];
				if(iBor != null && count < (this.numLabels - 1)) {
					menuBarStr += borderCell(iBor);
				}
			}
			if(oBor != null) {
				menuBarStr += borderCell(oBor);
				if (iBor != null) {
					menuBarStr += borderRow(oBor, ((this.numLabels * 2) + 1));
				}
				else {
					menuBarStr += borderRow(oBor, (this.numLabels + 2));
				}
			}
			menuBarStr += '</tr>';
		}

		menuBarStr += '</table></div>';
		document.write(menuBarStr);
	}
}


/* Menu
 *
 *  menuNo        - menu number
 *  menuWidth     - menu width
 *  orientation   - horizontal or vertical
 *  iBor          - inner border colour
 *  oBor          - outer border colour
 */
function Menu(menuNo, menuWidth, orientation, iBor, oBor) {

	// increment internal menu count
	currentMenuNo += 1;
	this.menuNo = menuNo;

	// menu item counter
	this.numItems = 0;

	// borders
	this.iBor = iBor;
	this.oBor = oBor;

	// default height
	this.height = 15;

	// html of the menu items
	this.itemText = new Array();
	this.rowText = new Array();

	// alignment
	this.align = 'left';

	// classes
	this.offClass = 'JSMenuItemLink';
	this.onClass = 'JSMenuItemLinkOn';

	// orientation
	this.orientation = orientation;

	// bullet point alignment (left | right)
	this.bulletAlign = 'left';

	// target type (self | iframe | frame | new)
	this.targetType = 'self';

	// target frame ( _self | _blank | (i)frame name)
	this.targetFrame = '_self';

	/* Add a menu item
	 *
	 *   bullet       - name of bullet, or null
	 *   labelText    - text to appear in the menu-label
	 *   menuNo       - menu number
	 *   labelWidth   - label width (pixels)
	 *   offColour    - background colour of the label's off state
	 *   onColour     - background colour of the label's on state
	 *   labelURL     - menu link URL
	 *   align        - text alignment
	 */
	this.add = function(bullet, itemText, menuNo, itemWidth, offColour, onColour, itemURL, align) {

		// increment internal counter
		this.numItems += 1;

		// create a unique ID for the menu item..
		var tempId = this.menuNo + '_' + this.numItems;

		// if the item pops up a menu
		if(menuNo != null) {
			tier[menuNo]            = tier[this.menuNo] + 1;
			onColours[menuNo]       = onColour;
			offColours[menuNo]      = offColour;
			onClass[menuNo]         = this.onClass;
			offClass[menuNo]        = this.offClass;
			labelBulletName[menuNo] = bullet;
			if(this.oBor != null) {
				borderMod[menuNo] = 1;
			}
			else {
				borderMod[menuNo] = 0;
			}
		}

		// create strings to hold the html for the menu item
		temp = new String('');
		this.rowText[this.numItems] = new String('');

		// if this is a submenu label...
		if(menuNo != null) {
			if(this.orientation =='vertical') {
				this.rowText[this.numItems] += '<tr id="labelRow'+ menuNo + '">';
			}
			temp += '<td id="labelCell'+ menuNo + '" width="'+ itemWidth +
			    '" bgcolor="' + offColour + '" valign="middle" ' +
			    'height="' + this.height + '" ';

		// no sub-menu
		} else {
			if(this.orientation =='vertical') {
				this.rowText[this.numItems] += '<tr>';
			}
			temp += '<td id="itemCell' + tempId + '" width="'+ itemWidth +
			    '" bgcolor="' + offColour + '" valign="middle" height="' +
			    this.height + '" class="JS' + align + 'Menu"';
		}

		// non NS
		if(!browser.ns4) {
			if(menuNo != null) {
				if(this.orientation =='vertical') {
					temp += ' onmouseover="menuOver(); return !showMenuSide(' + menuNo + ', event, tier[' + menuNo + ']); ' +
					    '" onmouseout=" menuOut(); "';
				}
				else {
					temp += ' onmouseover="menuOver(); return !showMenu(' + menuNo + ', event); '+
					'" onmouseout=" menuOut(); "';
				}
			} else {
				temp += ' onmouseover="changeClass(\'menuLink' + tempId + '\',\'' + this.onClass + '\');' +
				    'hideAllMenusTier(tier[' + this.menuNo + ']);' +
				    'menuOver();  ' +
				    'changeBGColour(\'itemCell' + tempId + '\', \'' + onColour + '\'); ' +
				    'changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.onImage\'); " ' +
				    'onmouseout="menuOut(); ' +
				    'changeClass(\'menuLink' + tempId + '\',\'' + this.offClass + '\'); '+
				    'changeBGColour(\'itemCell' + tempId + '\', \'' + offColour + '\'); ' +
				    'changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.offImage\'); "';
			}
		}
		temp += '>';

		// NS4
		if(browser.ns4) {
			temp += '<ilayer><layer ';
			if(menuNo != null) {
				if(this.orientation == 'vertical') {
					temp += 'onmouseover="menuOver(); return !showMenuSide(' + menuNo + ', event, ' +
					    'tier[' + menuNo + ']);" onmouseout="menuOut();"';
				}
				else {
					temp += 'onmouseover="menuOver(); return !showMenu(' + menuNo + ', event);' +
					    '" onmouseout="menuOut();"';
				}
			} else {
				temp += 'onmouseover="hideAllMenusTier(tier[' + this.menuNo + ']); menuOver(); ' +
				    'changeBGColour(\'menuItem' + tempId + '\', \'' + onColour + '\'); ' +
				    'changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.onImage\'); ' +
				    '"onmouseout="menuOut(); changeBGColour(\'menuItem' + tempId + '\', \'' + offColour + '\'); ' +
				    'changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.offImage\'); "';
			}
		} else {
			temp +='<div ';
		}

		// assign class and width
		temp += ' class="JSMenuItem' + align + '" width="' + itemWidth + '"';

		// id
		if(menuNo != null) {
			temp += ' id="menuLabel' + menuNo +'"';
		}
		else {
			temp += ' id="menuItem' + tempId +'"';
		}

		// URL
		temp += '><a href="' + itemURL +'" target="' + this.targetFrame + '" class="' + this.offClass + '"';
		if(menuNo != null) {
			temp += 'id="menuLink' + menuNo +'"';
		}
		else {
			temp += 'id="menuLink' + tempId +'"';
		}
		temp +='>';

		// if bullets are enabled...
		if (bullet != null) {
			if(menuNo != null) {
				temp += '<img src="' + eval(bullet + ".URL") + '" border="0" align="' + this.bulletAlign +
				    '" id="menuBullet' + menuNo + '" name="menuBullet' + menuNo + '">';
			}
			else {
				temp += '<img src="' + eval(bullet + ".URL") + '" border="0" align="' + this.bulletAlign +
				    '" id="menuItemBullet' + tempId + '" name="menuItemBullet' + tempId + '">';
			}
		}

		// close the link element
		temp += itemText + '</a>';

		if(browser.ns4) {
			temp += '</layer></ilayer>';
		}
		else {
			temp += '</div>';
		}

		temp += '</td>';
		this.itemText[this.numItems] = new String(temp);
	}


	// write the menu
	this.write = function() {

		var menuStr = new String();
		oBor = this.oBor;
		iBor = this.iBor;

		// any menu-items
		if(this.numItems == 0) {
			menuType[this.menuNo] = 'blank';
		}
		else {
			menuType[this.menuNo] = 'default';
		}

		// start a DIV element to hold the menu
		menuStr += '<div id="menu' + this.menuNo + '" name="menu' + this.menuNo + '" class="JSMenu" width="' + menuWidth + '"';

		// assign a width (NS4 can choke on "style" attributes)
		if(!browser.ns4) {
			menuStr += ' style="width:' + menuWidth + ';"';
		}

		// start the TABLE that hold the menu
		menuStr+= '><table border="0" cellpadding="0" cellspacing="0" width="' + menuWidth + '">';

		// if it's a vertical menu...
		if(this.orientation == 'vertical') {
			if(oBor != null) {
				menuStr += borderRow(this.oBor, 3);
			}

			// each label
			for(var count = 0; count < this.numItems; count++) {
				menuStr += this.rowText[count+1];
				if(oBor != null) {
					menuStr += borderCell(oBor);
				}
				menuStr += this.itemText[count+1];
				if(oBor != null) {
					menuStr += borderCell(oBor);
				}
				menuStr += '</tr>';
				if(iBor != null && count < (this.numItems - 1)) {
					if(oBor != null) {
						menuStr += '<tr>' + borderCell(oBor) + borderCell(iBor) + borderCell(oBor) + '</tr>';
					}
					else {
						menuStr += borderRow(iBor, 1);
					}
				}
			}
			if(oBor != null) {
				menuStr += borderRow(oBor, 3);
			}

		// horizontal
		} else {
			if(oBor != null) {
				if(iBor != null) {
					menuStr += borderRow(oBor, ((this.numItems * 2) + 1));
				}
				else {
					menuStr += borderRow(oBor, (this.numItems + 2));
				}
			}
			menuStr += '<tr>';
			if(oBor != null) {
				menuStr += borderCell(oBor);
			}
			for(var count = 0; count < this.numItems; count++) {
				menuStr += this.rowText[count+1];
				menuStr += this.itemText[count+1];
				if(iBor != null && count < (this.numItems-1)) {
					menuStr += borderCell(iBor);
				}
			}
			if(oBor != null) {
				menuStr += borderCell(oBor);
				if(iBor != null) {
					menuStr += borderRow(oBor, ((this.numItems * 2) + 1));
				}
				else {
					menuStr += borderRow(oBor, (this.numItems+2));
				}
			}
			menuStr +=  '</tr>';
		}

		// close the table and DIV elements
		menuStr += '</table></div>';

		// write it
		document.write(menuStr);
	}
}


// Bullet Point Object
function BulletPoint(offURL, onURL) {

	this.offImage     = new Image();
	this.offImage.src = offURL;
	this.onImage      = new Image();
	this.onImage.src  = onURL;
	this.URL          = String(offURL);
}



// expand a menu table
function expand_table(name) {

	alterElements('div', 'expanded_' + name, '');
	alterElements('div', 'collapsed_' + name, 'none');

	// set cookie so that the expanded table will be displayed
	set_cookie("expanded_" +name, "Y");
}


// collapse a menu table
function collapse_table(name) {

	alterElements("div", "expanded_" + name, 'none');
	alterElements("div", "collapsed_" + name, '');

	// set cookie so that the collapsed table will be displayed
	set_cookie("expanded_" +name, "N");
}



/*
* Loads up the customer menu preferences; determining whether or
* not particular menu tables specified by parameter 'name' should
* should be expanded/collapsed
*/
function loadCustMenuPrefs(name, default_value) {

	var displayExpandedTable = get_cookie("expanded_"+name);

	if (displayExpandedTable == null) {
		displayExpandedTable= default_value;
	}

	if (displayExpandedTable == "Y") {
		expand_table(name);
	} else {
		collapse_table(name);
	}
}



// Clear login fields
function clearLoginFields(name) {
	var form = document.forms[name];

	form.username.value = "";
	form.pwd.value = "";
}
/*
 * Promotion page javascript.
 * $Id: promotions.js,v 1.1.4.2.2.1 2010-08-16 17:16:07 tvass Exp $
 */

/*
 * Called on load, taken from the core main.js
 */
$(function () {
	$('div.promotionTable div.header a').click(function(e){
		e.preventDefault();
		$(this).blur();
		$(this).parents('.promotionTable').find('table').toggle('fast');
		$(this).parents('.promotionTable').toggleClass('open');
		$(this).text($(this).text() == 'Show Details' ? 'Hide Details' : 'Show Details');
		});
	$('body.promotions #Body div.promotion div.section h3').click(function(){
		$(this).parent('.section').find('ul').toggle('fast');
		$(this).parent('.section').toggleClass('closed');
		}); 
});
/*
 * jQuery Cycle Plugin (core)
 * Examples and documentation at: http://jquery.malsup.com/cycle/
 * Copyright (c) 2007-2010 M. Alsup
 * Version: 2.86 (05-APR-2010)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires: jQuery v1.2.6 or later
 */
(function($){var ver="2.86";if($.support==undefined){$.support={opacity:!($.browser.msie)};}function debug(s){if($.fn.cycle.debug){log(s);}}function log(){if(window.console&&window.console.log){window.console.log("[cycle] "+Array.prototype.join.call(arguments," "));}}$.fn.cycle=function(options,arg2){var o={s:this.selector,c:this.context};if(this.length===0&&options!="stop"){if(!$.isReady&&o.s){log("DOM not ready, queuing slideshow");$(function(){$(o.s,o.c).cycle(options,arg2);});return this;}log("terminating; zero elements found by selector"+($.isReady?"":" (DOM not ready)"));return this;}return this.each(function(){var opts=handleArguments(this,options,arg2);if(opts===false){return;}opts.updateActivePagerLink=opts.updateActivePagerLink||$.fn.cycle.updateActivePagerLink;if(this.cycleTimeout){clearTimeout(this.cycleTimeout);}this.cycleTimeout=this.cyclePause=0;var $cont=$(this);var $slides=opts.slideExpr?$(opts.slideExpr,this):$cont.children();var els=$slides.get();if(els.length<2){log("terminating; too few slides: "+els.length);return;}var opts2=buildOptions($cont,$slides,els,opts,o);if(opts2===false){return;}var startTime=opts2.continuous?10:getTimeout(opts2.currSlide,opts2.nextSlide,opts2,!opts2.rev);if(startTime){startTime+=(opts2.delay||0);if(startTime<10){startTime=10;}debug("first timeout: "+startTime);this.cycleTimeout=setTimeout(function(){go(els,opts2,0,!opts2.rev);},startTime);}});};function handleArguments(cont,options,arg2){if(cont.cycleStop==undefined){cont.cycleStop=0;}if(options===undefined||options===null){options={};}if(options.constructor==String){switch(options){case"destroy":case"stop":var opts=$(cont).data("cycle.opts");if(!opts){return false;}cont.cycleStop++;if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);}cont.cycleTimeout=0;$(cont).removeData("cycle.opts");if(options=="destroy"){destroy(opts);}return false;case"toggle":cont.cyclePause=(cont.cyclePause===1)?0:1;checkInstantResume(cont.cyclePause,arg2,cont);return false;case"pause":cont.cyclePause=1;return false;case"resume":cont.cyclePause=0;checkInstantResume(false,arg2,cont);return false;case"prev":case"next":var opts=$(cont).data("cycle.opts");if(!opts){log('options not found, "prev/next" ignored');return false;}$.fn.cycle[options](opts);return false;default:options={fx:options};}return options;}else{if(options.constructor==Number){var num=options;options=$(cont).data("cycle.opts");if(!options){log("options not found, can not advance slide");return false;}if(num<0||num>=options.elements.length){log("invalid slide index: "+num);return false;}options.nextSlide=num;if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);cont.cycleTimeout=0;}if(typeof arg2=="string"){options.oneTimeFx=arg2;}go(options.elements,options,1,num>=options.currSlide);return false;}}return options;function checkInstantResume(isPaused,arg2,cont){if(!isPaused&&arg2===true){var options=$(cont).data("cycle.opts");if(!options){log("options not found, can not resume");return false;}if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);cont.cycleTimeout=0;}go(options.elements,options,1,1);}}}function removeFilter(el,opts){if(!$.support.opacity&&opts.cleartype&&el.style.filter){try{el.style.removeAttribute("filter");}catch(smother){}}}function destroy(opts){if(opts.next){$(opts.next).unbind(opts.prevNextEvent);}if(opts.prev){$(opts.prev).unbind(opts.prevNextEvent);}if(opts.pager||opts.pagerAnchorBuilder){$.each(opts.pagerAnchors||[],function(){this.unbind().remove();});}opts.pagerAnchors=null;if(opts.destroy){opts.destroy(opts);}}function buildOptions($cont,$slides,els,options,o){var opts=$.extend({},$.fn.cycle.defaults,options||{},$.metadata?$cont.metadata():$.meta?$cont.data():{});if(opts.autostop){opts.countdown=opts.autostopCount||els.length;}var cont=$cont[0];$cont.data("cycle.opts",opts);opts.$cont=$cont;opts.stopCount=cont.cycleStop;opts.elements=els;opts.before=opts.before?[opts.before]:[];opts.after=opts.after?[opts.after]:[];opts.after.unshift(function(){opts.busy=0;});if(!$.support.opacity&&opts.cleartype){opts.after.push(function(){removeFilter(this,opts);});}if(opts.continuous){opts.after.push(function(){go(els,opts,0,!opts.rev);});}saveOriginalOpts(opts);if(!$.support.opacity&&opts.cleartype&&!opts.cleartypeNoBg){clearTypeFix($slides);}if($cont.css("position")=="static"){$cont.css("position","relative");}if(opts.width){$cont.width(opts.width);}if(opts.height&&opts.height!="auto"){$cont.height(opts.height);}if(opts.startingSlide){opts.startingSlide=parseInt(opts.startingSlide);}if(opts.random){opts.randomMap=[];for(var i=0;i<els.length;i++){opts.randomMap.push(i);}opts.randomMap.sort(function(a,b){return Math.random()-0.5;});opts.randomIndex=1;opts.startingSlide=opts.randomMap[1];}else{if(opts.startingSlide>=els.length){opts.startingSlide=0;}}opts.currSlide=opts.startingSlide||0;var first=opts.startingSlide;$slides.css({position:"absolute",top:0,left:0}).hide().each(function(i){var z=first?i>=first?els.length-(i-first):first-i:els.length-i;$(this).css("z-index",z);});$(els[first]).css("opacity",1).show();removeFilter(els[first],opts);if(opts.fit&&opts.width){$slides.width(opts.width);}if(opts.fit&&opts.height&&opts.height!="auto"){$slides.height(opts.height);}var reshape=opts.containerResize&&!$cont.innerHeight();if(reshape){var maxw=0,maxh=0;for(var j=0;j<els.length;j++){var $e=$(els[j]),e=$e[0],w=$e.outerWidth(),h=$e.outerHeight();if(!w){w=e.offsetWidth||e.width||$e.attr("width");}if(!h){h=e.offsetHeight||e.height||$e.attr("height");}maxw=w>maxw?w:maxw;maxh=h>maxh?h:maxh;}if(maxw>0&&maxh>0){$cont.css({width:maxw+"px",height:maxh+"px"});}}if(opts.pause){$cont.hover(function(){this.cyclePause++;},function(){this.cyclePause--;});}if(supportMultiTransitions(opts)===false){return false;}var requeue=false;options.requeueAttempts=options.requeueAttempts||0;$slides.each(function(){var $el=$(this);this.cycleH=(opts.fit&&opts.height)?opts.height:($el.height()||this.offsetHeight||this.height||$el.attr("height")||0);this.cycleW=(opts.fit&&opts.width)?opts.width:($el.width()||this.offsetWidth||this.width||$el.attr("width")||0);if($el.is("img")){var loadingIE=($.browser.msie&&this.cycleW==28&&this.cycleH==30&&!this.complete);var loadingFF=($.browser.mozilla&&this.cycleW==34&&this.cycleH==19&&!this.complete);var loadingOp=($.browser.opera&&((this.cycleW==42&&this.cycleH==19)||(this.cycleW==37&&this.cycleH==17))&&!this.complete);var loadingOther=(this.cycleH==0&&this.cycleW==0&&!this.complete);if(loadingIE||loadingFF||loadingOp||loadingOther){if(o.s&&opts.requeueOnImageNotLoaded&&++options.requeueAttempts<100){log(options.requeueAttempts," - img slide not loaded, requeuing slideshow: ",this.src,this.cycleW,this.cycleH);setTimeout(function(){$(o.s,o.c).cycle(options);},opts.requeueTimeout);requeue=true;return false;}else{log("could not determine size of image: "+this.src,this.cycleW,this.cycleH);}}}return true;});if(requeue){return false;}opts.cssBefore=opts.cssBefore||{};opts.animIn=opts.animIn||{};opts.animOut=opts.animOut||{};$slides.not(":eq("+first+")").css(opts.cssBefore);if(opts.cssFirst){$($slides[first]).css(opts.cssFirst);}if(opts.timeout){opts.timeout=parseInt(opts.timeout);if(opts.speed.constructor==String){opts.speed=$.fx.speeds[opts.speed]||parseInt(opts.speed);}if(!opts.sync){opts.speed=opts.speed/2;}var buffer=opts.fx=="shuffle"?500:250;while((opts.timeout-opts.speed)<buffer){opts.timeout+=opts.speed;}}if(opts.easing){opts.easeIn=opts.easeOut=opts.easing;}if(!opts.speedIn){opts.speedIn=opts.speed;}if(!opts.speedOut){opts.speedOut=opts.speed;}opts.slideCount=els.length;opts.currSlide=opts.lastSlide=first;if(opts.random){if(++opts.randomIndex==els.length){opts.randomIndex=0;}opts.nextSlide=opts.randomMap[opts.randomIndex];}else{opts.nextSlide=opts.startingSlide>=(els.length-1)?0:opts.startingSlide+1;}if(!opts.multiFx){var init=$.fn.cycle.transitions[opts.fx];if($.isFunction(init)){init($cont,$slides,opts);}else{if(opts.fx!="custom"&&!opts.multiFx){log("unknown transition: "+opts.fx,"; slideshow terminating");return false;}}}var e0=$slides[first];if(opts.before.length){opts.before[0].apply(e0,[e0,e0,opts,true]);}if(opts.after.length>1){opts.after[1].apply(e0,[e0,e0,opts,true]);}if(opts.next){$(opts.next).bind(opts.prevNextEvent,function(){return advance(opts,opts.rev?-1:1);});}if(opts.prev){$(opts.prev).bind(opts.prevNextEvent,function(){return advance(opts,opts.rev?1:-1);});}if(opts.pager||opts.pagerAnchorBuilder){buildPager(els,opts);}exposeAddSlide(opts,els);return opts;}function saveOriginalOpts(opts){opts.original={before:[],after:[]};opts.original.cssBefore=$.extend({},opts.cssBefore);opts.original.cssAfter=$.extend({},opts.cssAfter);opts.original.animIn=$.extend({},opts.animIn);opts.original.animOut=$.extend({},opts.animOut);$.each(opts.before,function(){opts.original.before.push(this);});$.each(opts.after,function(){opts.original.after.push(this);});}function supportMultiTransitions(opts){var i,tx,txs=$.fn.cycle.transitions;if(opts.fx.indexOf(",")>0){opts.multiFx=true;opts.fxs=opts.fx.replace(/\s*/g,"").split(",");for(i=0;i<opts.fxs.length;i++){var fx=opts.fxs[i];tx=txs[fx];if(!tx||!txs.hasOwnProperty(fx)||!$.isFunction(tx)){log("discarding unknown transition: ",fx);opts.fxs.splice(i,1);i--;}}if(!opts.fxs.length){log("No valid transitions named; slideshow terminating.");return false;}}else{if(opts.fx=="all"){opts.multiFx=true;opts.fxs=[];for(p in txs){tx=txs[p];if(txs.hasOwnProperty(p)&&$.isFunction(tx)){opts.fxs.push(p);}}}}if(opts.multiFx&&opts.randomizeEffects){var r1=Math.floor(Math.random()*20)+30;for(i=0;i<r1;i++){var r2=Math.floor(Math.random()*opts.fxs.length);opts.fxs.push(opts.fxs.splice(r2,1)[0]);}debug("randomized fx sequence: ",opts.fxs);}return true;}function exposeAddSlide(opts,els){opts.addSlide=function(newSlide,prepend){var $s=$(newSlide),s=$s[0];if(!opts.autostopCount){opts.countdown++;}els[prepend?"unshift":"push"](s);if(opts.els){opts.els[prepend?"unshift":"push"](s);}opts.slideCount=els.length;$s.css("position","absolute");$s[prepend?"prependTo":"appendTo"](opts.$cont);if(prepend){opts.currSlide++;opts.nextSlide++;}if(!$.support.opacity&&opts.cleartype&&!opts.cleartypeNoBg){clearTypeFix($s);}if(opts.fit&&opts.width){$s.width(opts.width);}if(opts.fit&&opts.height&&opts.height!="auto"){$slides.height(opts.height);}s.cycleH=(opts.fit&&opts.height)?opts.height:$s.height();s.cycleW=(opts.fit&&opts.width)?opts.width:$s.width();$s.css(opts.cssBefore);if(opts.pager||opts.pagerAnchorBuilder){$.fn.cycle.createPagerAnchor(els.length-1,s,$(opts.pager),els,opts);}if($.isFunction(opts.onAddSlide)){opts.onAddSlide($s);}else{$s.hide();}};}$.fn.cycle.resetState=function(opts,fx){fx=fx||opts.fx;opts.before=[];opts.after=[];opts.cssBefore=$.extend({},opts.original.cssBefore);opts.cssAfter=$.extend({},opts.original.cssAfter);opts.animIn=$.extend({},opts.original.animIn);opts.animOut=$.extend({},opts.original.animOut);opts.fxFn=null;$.each(opts.original.before,function(){opts.before.push(this);});$.each(opts.original.after,function(){opts.after.push(this);});var init=$.fn.cycle.transitions[fx];if($.isFunction(init)){init(opts.$cont,$(opts.elements),opts);}};function go(els,opts,manual,fwd){if(manual&&opts.busy&&opts.manualTrump){debug("manualTrump in go(), stopping active transition");$(els).stop(true,true);opts.busy=false;}if(opts.busy){debug("transition active, ignoring new tx request");return;}var p=opts.$cont[0],curr=els[opts.currSlide],next=els[opts.nextSlide];if(p.cycleStop!=opts.stopCount||p.cycleTimeout===0&&!manual){return;}if(!manual&&!p.cyclePause&&((opts.autostop&&(--opts.countdown<=0))||(opts.nowrap&&!opts.random&&opts.nextSlide<opts.currSlide))){if(opts.end){opts.end(opts);}return;}var changed=false;if((manual||!p.cyclePause)&&(opts.nextSlide!=opts.currSlide)){changed=true;var fx=opts.fx;curr.cycleH=curr.cycleH||$(curr).height();curr.cycleW=curr.cycleW||$(curr).width();next.cycleH=next.cycleH||$(next).height();next.cycleW=next.cycleW||$(next).width();if(opts.multiFx){if(opts.lastFx==undefined||++opts.lastFx>=opts.fxs.length){opts.lastFx=0;}fx=opts.fxs[opts.lastFx];opts.currFx=fx;}if(opts.oneTimeFx){fx=opts.oneTimeFx;opts.oneTimeFx=null;}$.fn.cycle.resetState(opts,fx);if(opts.before.length){$.each(opts.before,function(i,o){if(p.cycleStop!=opts.stopCount){return;}o.apply(next,[curr,next,opts,fwd]);});}var after=function(){$.each(opts.after,function(i,o){if(p.cycleStop!=opts.stopCount){return;}o.apply(next,[curr,next,opts,fwd]);});};debug("tx firing; currSlide: "+opts.currSlide+"; nextSlide: "+opts.nextSlide);opts.busy=1;if(opts.fxFn){opts.fxFn(curr,next,opts,after,fwd,manual&&opts.fastOnEvent);}else{if($.isFunction($.fn.cycle[opts.fx])){$.fn.cycle[opts.fx](curr,next,opts,after,fwd,manual&&opts.fastOnEvent);}else{$.fn.cycle.custom(curr,next,opts,after,fwd,manual&&opts.fastOnEvent);}}}if(changed||opts.nextSlide==opts.currSlide){opts.lastSlide=opts.currSlide;if(opts.random){opts.currSlide=opts.nextSlide;if(++opts.randomIndex==els.length){opts.randomIndex=0;}opts.nextSlide=opts.randomMap[opts.randomIndex];if(opts.nextSlide==opts.currSlide){opts.nextSlide=(opts.currSlide==opts.slideCount-1)?0:opts.currSlide+1;}}else{var roll=(opts.nextSlide+1)==els.length;opts.nextSlide=roll?0:opts.nextSlide+1;opts.currSlide=roll?els.length-1:opts.nextSlide-1;}}if(changed&&opts.pager){opts.updateActivePagerLink(opts.pager,opts.currSlide,opts.activePagerClass);}var ms=0;if(opts.timeout&&!opts.continuous){ms=getTimeout(curr,next,opts,fwd);}else{if(opts.continuous&&p.cyclePause){ms=10;}}if(ms>0){p.cycleTimeout=setTimeout(function(){go(els,opts,0,!opts.rev);},ms);}}$.fn.cycle.updateActivePagerLink=function(pager,currSlide,clsName){$(pager).each(function(){$(this).children().removeClass(clsName).eq(currSlide).addClass(clsName);});};function getTimeout(curr,next,opts,fwd){if(opts.timeoutFn){var t=opts.timeoutFn(curr,next,opts,fwd);while((t-opts.speed)<250){t+=opts.speed;}debug("calculated timeout: "+t+"; speed: "+opts.speed);if(t!==false){return t;}}return opts.timeout;}$.fn.cycle.next=function(opts){advance(opts,opts.rev?-1:1);};$.fn.cycle.prev=function(opts){advance(opts,opts.rev?1:-1);};function advance(opts,val){var els=opts.elements;var p=opts.$cont[0],timeout=p.cycleTimeout;if(timeout){clearTimeout(timeout);p.cycleTimeout=0;}if(opts.random&&val<0){opts.randomIndex--;if(--opts.randomIndex==-2){opts.randomIndex=els.length-2;}else{if(opts.randomIndex==-1){opts.randomIndex=els.length-1;}}opts.nextSlide=opts.randomMap[opts.randomIndex];}else{if(opts.random){opts.nextSlide=opts.randomMap[opts.randomIndex];}else{opts.nextSlide=opts.currSlide+val;if(opts.nextSlide<0){if(opts.nowrap){return false;}opts.nextSlide=els.length-1;}else{if(opts.nextSlide>=els.length){if(opts.nowrap){return false;}opts.nextSlide=0;}}}}var cb=opts.onPrevNextEvent||opts.prevNextClick;if($.isFunction(cb)){cb(val>0,opts.nextSlide,els[opts.nextSlide]);}go(els,opts,1,val>=0);return false;}function buildPager(els,opts){var $p=$(opts.pager);$.each(els,function(i,o){$.fn.cycle.createPagerAnchor(i,o,$p,els,opts);});opts.updateActivePagerLink(opts.pager,opts.startingSlide,opts.activePagerClass);}$.fn.cycle.createPagerAnchor=function(i,el,$p,els,opts){var a;if($.isFunction(opts.pagerAnchorBuilder)){a=opts.pagerAnchorBuilder(i,el);debug("pagerAnchorBuilder("+i+", el) returned: "+a);}else{a='<a href="#">'+(i+1)+"</a>";}if(!a){return;}var $a=$(a);if($a.parents("body").length===0){var arr=[];if($p.length>1){$p.each(function(){var $clone=$a.clone(true);$(this).append($clone);arr.push($clone[0]);});$a=$(arr);}else{$a.appendTo($p);}}opts.pagerAnchors=opts.pagerAnchors||[];opts.pagerAnchors.push($a);$a.bind(opts.pagerEvent,function(e){e.preventDefault();opts.nextSlide=i;var p=opts.$cont[0],timeout=p.cycleTimeout;if(timeout){clearTimeout(timeout);p.cycleTimeout=0;}var cb=opts.onPagerEvent||opts.pagerClick;if($.isFunction(cb)){cb(opts.nextSlide,els[opts.nextSlide]);}go(els,opts,1,opts.currSlide<i);});if(!/^click/.test(opts.pagerEvent)&&!opts.allowPagerClickBubble){$a.bind("click.cycle",function(){return false;});}if(opts.pauseOnPagerHover){$a.hover(function(){opts.$cont[0].cyclePause++;},function(){opts.$cont[0].cyclePause--;});}};$.fn.cycle.hopsFromLast=function(opts,fwd){var hops,l=opts.lastSlide,c=opts.currSlide;if(fwd){hops=c>l?c-l:opts.slideCount-l;}else{hops=c<l?l-c:l+opts.slideCount-c;}return hops;};function clearTypeFix($slides){debug("applying clearType background-color hack");function hex(s){s=parseInt(s).toString(16);return s.length<2?"0"+s:s;}function getBg(e){for(;e&&e.nodeName.toLowerCase()!="html";e=e.parentNode){var v=$.css(e,"background-color");if(v.indexOf("rgb")>=0){var rgb=v.match(/\d+/g);return"#"+hex(rgb[0])+hex(rgb[1])+hex(rgb[2]);}if(v&&v!="transparent"){return v;}}return"#ffffff";}$slides.each(function(){$(this).css("background-color",getBg(this));});}$.fn.cycle.commonReset=function(curr,next,opts,w,h,rev){$(opts.elements).not(curr).hide();opts.cssBefore.opacity=1;opts.cssBefore.display="block";if(w!==false&&next.cycleW>0){opts.cssBefore.width=next.cycleW;}if(h!==false&&next.cycleH>0){opts.cssBefore.height=next.cycleH;}opts.cssAfter=opts.cssAfter||{};opts.cssAfter.display="none";$(curr).css("zIndex",opts.slideCount+(rev===true?1:0));$(next).css("zIndex",opts.slideCount+(rev===true?0:1));};$.fn.cycle.custom=function(curr,next,opts,cb,fwd,speedOverride){var $l=$(curr),$n=$(next);var speedIn=opts.speedIn,speedOut=opts.speedOut,easeIn=opts.easeIn,easeOut=opts.easeOut;$n.css(opts.cssBefore);if(speedOverride){if(typeof speedOverride=="number"){speedIn=speedOut=speedOverride;}else{speedIn=speedOut=1;}easeIn=easeOut=null;}var fn=function(){$n.animate(opts.animIn,speedIn,easeIn,cb);};$l.animate(opts.animOut,speedOut,easeOut,function(){if(opts.cssAfter){$l.css(opts.cssAfter);}if(!opts.sync){fn();}});if(opts.sync){fn();}};$.fn.cycle.transitions={fade:function($cont,$slides,opts){$slides.not(":eq("+opts.currSlide+")").css("opacity",0);opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts);opts.cssBefore.opacity=0;});opts.animIn={opacity:1};opts.animOut={opacity:0};opts.cssBefore={top:0,left:0};}};$.fn.cycle.ver=function(){return ver;};$.fn.cycle.defaults={fx:"fade",timeout:4000,timeoutFn:null,continuous:0,speed:1000,speedIn:null,speedOut:null,next:null,prev:null,onPrevNextEvent:null,prevNextEvent:"click.cycle",pager:null,onPagerEvent:null,pagerEvent:"click.cycle",allowPagerClickBubble:false,pagerAnchorBuilder:null,before:null,after:null,end:null,easing:null,easeIn:null,easeOut:null,shuffle:null,animIn:null,animOut:null,cssBefore:null,cssAfter:null,fxFn:null,height:"auto",startingSlide:0,sync:1,random:0,fit:0,containerResize:1,pause:0,pauseOnPagerHover:0,autostop:0,autostopCount:0,delay:0,slideExpr:null,cleartype:!$.support.opacity,cleartypeNoBg:false,nowrap:0,fastOnEvent:0,randomizeEffects:1,rev:0,manualTrump:true,requeueOnImageNotLoaded:true,requeueTimeout:250,activePagerClass:"activeSlide",updateActivePagerLink:null};})(jQuery);/*!
 * jCarousel - Riding carousels with jQuery
 *   http://sorgalla.com/jcarousel/
 *
 * Copyright (c) 2006 Jan Sorgalla (http://sorgalla.com)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Built on top of the jQuery library
 *   http://jquery.com
 *
 * Inspired by the "Carousel Component" by Bill Scott
 *   http://billwscott.com/carousel/
 */

(function($){$.fn.jcarousel=function(o){if(typeof o=='string'){var instance=$(this).data('jcarousel'),args=Array.prototype.slice.call(arguments,1);return instance[o].apply(instance,args);}else
return this.each(function(){$(this).data('jcarousel',new $jc(this,o));});};var defaults={vertical:false,start:1,offset:1,size:null,scroll:3,visible:null,animation:'normal',easing:'swing',auto:0,wrap:null,initCallback:null,reloadCallback:null,itemLoadCallback:null,itemFirstInCallback:null,itemFirstOutCallback:null,itemLastInCallback:null,itemLastOutCallback:null,itemVisibleInCallback:null,itemVisibleOutCallback:null,buttonNextHTML:'<div></div>',buttonPrevHTML:'<div></div>',buttonNextEvent:'click',buttonPrevEvent:'click',buttonNextCallback:null,buttonPrevCallback:null};$.jcarousel=function(e,o){this.options=$.extend({},defaults,o||{});this.locked=false;this.container=null;this.clip=null;this.list=null;this.buttonNext=null;this.buttonPrev=null;this.wh=!this.options.vertical?'width':'height';this.lt=!this.options.vertical?'left':'top';var skin='',split=e.className.split(' ');for(var i=0;i<split.length;i++){if(split[i].indexOf('jcarousel-skin')!=-1){$(e).removeClass(split[i]);skin=split[i];break;}}if(e.nodeName=='UL'||e.nodeName=='OL'){this.list=$(e);this.container=this.list.parent();if(this.container.hasClass('jcarousel-clip')){if(!this.container.parent().hasClass('jcarousel-container'))this.container=this.container.wrap('<div></div>');this.container=this.container.parent();}else if(!this.container.hasClass('jcarousel-container'))this.container=this.list.wrap('<div></div>').parent();}else{this.container=$(e);this.list=this.container.find('ul,ol').eq(0);}if(skin!=''&&this.container.parent()[0].className.indexOf('jcarousel-skin')==-1)this.container.wrap('<div class=" '+skin+'"></div>');this.clip=this.list.parent();if(!this.clip.length||!this.clip.hasClass('jcarousel-clip'))this.clip=this.list.wrap('<div></div>').parent();this.buttonNext=$('.jcarousel-next',this.container);if(this.buttonNext.size()==0&&this.options.buttonNextHTML!=null)this.buttonNext=this.clip.after(this.options.buttonNextHTML).next();this.buttonNext.addClass(this.className('jcarousel-next'));this.buttonPrev=$('.jcarousel-prev',this.container);if(this.buttonPrev.size()==0&&this.options.buttonPrevHTML!=null)this.buttonPrev=this.clip.after(this.options.buttonPrevHTML).next();this.buttonPrev.addClass(this.className('jcarousel-prev'));this.clip.addClass(this.className('jcarousel-clip')).css({overflow:'hidden',position:'relative'});this.list.addClass(this.className('jcarousel-list')).css({overflow:'hidden',position:'relative',top:0,left:0,margin:0,padding:0});this.container.addClass(this.className('jcarousel-container')).css({position:'relative'});var di=this.options.visible!=null?Math.ceil(this.clipping()/this.options.visible):null;var li=this.list.children('li');var self=this;if(li.size()>0){var wh=0,i=this.options.offset;li.each(function(){self.format(this,i++);wh+=self.dimension(this,di);});this.list.css(this.wh,wh+'px');if(!o||o.size===undefined)this.options.size=li.size();}this.container.css('display','block');this.buttonNext.css('display','block');this.buttonPrev.css('display','block');this.funcNext=function(){self.next();};this.funcPrev=function(){self.prev();};this.funcResize=function(){self.reload();};if(this.options.initCallback!=null)this.options.initCallback(this,'init');if($.browser.safari){this.buttons(false,false);$(window).bind('load.jcarousel',function(){self.setup();});}else
this.setup();};var $jc=$.jcarousel;$jc.fn=$jc.prototype={jcarousel:'0.2.4'};$jc.fn.extend=$jc.extend=$.extend;$jc.fn.extend({setup:function(){this.first=null;this.last=null;this.prevFirst=null;this.prevLast=null;this.animating=false;this.timer=null;this.tail=null;this.inTail=false;if(this.locked)return;this.list.css(this.lt,this.pos(this.options.offset)+'px');var p=this.pos(this.options.start);this.prevFirst=this.prevLast=null;this.animate(p,false);$(window).unbind('resize.jcarousel',this.funcResize).bind('resize.jcarousel',this.funcResize);},reset:function(){this.list.empty();this.list.css(this.lt,'0px');this.list.css(this.wh,'10px');if(this.options.initCallback!=null)this.options.initCallback(this,'reset');this.setup();},reload:function(){if(this.tail!=null&&this.inTail)this.list.css(this.lt,$jc.intval(this.list.css(this.lt))+this.tail);this.tail=null;this.inTail=false;if(this.options.reloadCallback!=null)this.options.reloadCallback(this);if(this.options.visible!=null){var self=this;var di=Math.ceil(this.clipping()/this.options.visible),wh=0,lt=0;$('li',this.list).each(function(i){wh+=self.dimension(this,di);if(i+1<self.first)lt=wh;});this.list.css(this.wh,wh+'px');this.list.css(this.lt,-lt+'px');}this.scroll(this.first,false);},lock:function(){this.locked=true;this.buttons();},unlock:function(){this.locked=false;this.buttons();},size:function(s){if(s!=undefined){this.options.size=s;if(!this.locked)this.buttons();}return this.options.size;},has:function(i,i2){if(i2==undefined||!i2)i2=i;if(this.options.size!==null&&i2>this.options.size)i2=this.options.size;for(var j=i;j<=i2;j++){var e=this.get(j);if(!e.length||e.hasClass('jcarousel-item-placeholder'))return false;}return true;},get:function(i){return $('.jcarousel-item-'+i,this.list);},add:function(i,s){var e=this.get(i),old=0,add=0;if(e.length==0){var c,e=this.create(i),j=$jc.intval(i);while(c=this.get(--j)){if(j<=0||c.length){j<=0?this.list.prepend(e):c.after(e);break;}}}else
old=this.dimension(e);e.removeClass(this.className('jcarousel-item-placeholder'));typeof s=='string'?e.html(s):e.empty().append(s);var di=this.options.visible!=null?Math.ceil(this.clipping()/this.options.visible):null;var wh=this.dimension(e,di)-old;if(i>0&&i<this.first)this.list.css(this.lt,$jc.intval(this.list.css(this.lt))-wh+'px');this.list.css(this.wh,$jc.intval(this.list.css(this.wh))+wh+'px');return e;},remove:function(i){var e=this.get(i);if(!e.length||(i>=this.first&&i<=this.last))return;var d=this.dimension(e);if(i<this.first)this.list.css(this.lt,$jc.intval(this.list.css(this.lt))+d+'px');e.remove();this.list.css(this.wh,$jc.intval(this.list.css(this.wh))-d+'px');},next:function(){this.stopAuto();if(this.tail!=null&&!this.inTail)this.scrollTail(false);else
this.scroll(((this.options.wrap=='both'||this.options.wrap=='last')&&this.options.size!=null&&this.last==this.options.size)?1:this.first+this.options.scroll);},prev:function(){this.stopAuto();if(this.tail!=null&&this.inTail)this.scrollTail(true);else
this.scroll(((this.options.wrap=='both'||this.options.wrap=='first')&&this.options.size!=null&&this.first==1)?this.options.size:this.first-this.options.scroll);},scrollTail:function(b){if(this.locked||this.animating||!this.tail)return;var pos=$jc.intval(this.list.css(this.lt));!b?pos-=this.tail:pos+=this.tail;this.inTail=!b;this.prevFirst=this.first;this.prevLast=this.last;this.animate(pos);},scroll:function(i,a){if(this.locked||this.animating)return;this.animate(this.pos(i),a);},pos:function(i){var pos=$jc.intval(this.list.css(this.lt));if(this.locked||this.animating)return pos;if(this.options.wrap!='circular')i=i<1?1:(this.options.size&&i>this.options.size?this.options.size:i);var back=this.first>i;var f=this.options.wrap!='circular'&&this.first<=1?1:this.first;var c=back?this.get(f):this.get(this.last);var j=back?f:f-1;var e=null,l=0,p=false,d=0,g;while(back?--j>=i:++j<i){e=this.get(j);p=!e.length;if(e.length==0){e=this.create(j).addClass(this.className('jcarousel-item-placeholder'));c[back?'before':'after'](e);if(this.first!=null&&this.options.wrap=='circular'&&this.options.size!==null&&(j<=0||j>this.options.size)){g=this.get(this.index(j));if(g.length)this.add(j,g.children().clone(true));}}c=e;d=this.dimension(e);if(p)l+=d;if(this.first!=null&&(this.options.wrap=='circular'||(j>=1&&(this.options.size==null||j<=this.options.size))))pos=back?pos+d:pos-d;}var clipping=this.clipping();var cache=[];var visible=0,j=i,v=0;var c=this.get(i-1);while(++visible){e=this.get(j);p=!e.length;if(e.length==0){e=this.create(j).addClass(this.className('jcarousel-item-placeholder'));c.length==0?this.list.prepend(e):c[back?'before':'after'](e);if(this.first!=null&&this.options.wrap=='circular'&&this.options.size!==null&&(j<=0||j>this.options.size)){g=this.get(this.index(j));if(g.length)this.add(j,g.find('>*').clone(true));}}c=e;var d=this.dimension(e);if(d==0){alert('jCarousel: No width/height set for items. This will cause an infinite loop. Aborting...');return 0;}if(this.options.wrap!='circular'&&this.options.size!==null&&j>this.options.size)cache.push(e);else if(p)l+=d;v+=d;if(v>=clipping)break;j++;}for(var x=0;x<cache.length;x++)cache[x].remove();if(l>0){this.list.css(this.wh,this.dimension(this.list)+l+'px');if(back){pos-=l;this.list.css(this.lt,$jc.intval(this.list.css(this.lt))-l+'px');}}var last=i+visible-1;if(this.options.wrap!='circular'&&this.options.size&&last>this.options.size)last=this.options.size;if(j>last){visible=0,j=last,v=0;while(++visible){var e=this.get(j--);if(!e.length)break;v+=this.dimension(e);if(v>=clipping)break;}}var first=last-visible+1;if(this.options.wrap!='circular'&&first<1)first=1;if(this.inTail&&back){pos+=this.tail;this.inTail=false;}this.tail=null;if(this.options.wrap!='circular'&&last==this.options.size&&(last-visible+1)>=1){var m=$jc.margin(this.get(last),!this.options.vertical?'marginRight':'marginBottom');if((v-m)>clipping)this.tail=v-clipping-m;}while(i-->first)pos+=this.dimension(this.get(i));this.prevFirst=this.first;this.prevLast=this.last;this.first=first;this.last=last;return pos;},animate:function(p,a){if(this.locked||this.animating)return;this.animating=true;var self=this;var scrolled=function(){self.animating=false;if(p==0)self.list.css(self.lt,0);if(self.options.wrap=='circular'||self.options.wrap=='both'||self.options.wrap=='last'||self.options.size==null||self.last<self.options.size)self.startAuto();self.buttons();self.notify('onAfterAnimation');};this.notify('onBeforeAnimation');if(!this.options.animation||a==false){this.list.css(this.lt,p+'px');scrolled();}else{var o=!this.options.vertical?{'left':p}:{'top':p};this.list.animate(o,this.options.animation,this.options.easing,scrolled);}},startAuto:function(s){if(s!=undefined)this.options.auto=s;if(this.options.auto==0)return this.stopAuto();if(this.timer!=null)return;var self=this;this.timer=setTimeout(function(){self.next();},this.options.auto*1000);},stopAuto:function(){if(this.timer==null)return;clearTimeout(this.timer);this.timer=null;},buttons:function(n,p){if(n==undefined||n==null){var n=!this.locked&&this.options.size!==0&&((this.options.wrap&&this.options.wrap!='first')||this.options.size==null||this.last<this.options.size);if(!this.locked&&(!this.options.wrap||this.options.wrap=='first')&&this.options.size!=null&&this.last>=this.options.size)n=this.tail!=null&&!this.inTail;}if(p==undefined||p==null){var p=!this.locked&&this.options.size!==0&&((this.options.wrap&&this.options.wrap!='last')||this.first>1);if(!this.locked&&(!this.options.wrap||this.options.wrap=='last')&&this.options.size!=null&&this.first==1)p=this.tail!=null&&this.inTail;}var self=this;this.buttonNext[n?'bind':'unbind'](this.options.buttonNextEvent+'.jcarousel',this.funcNext)[n?'removeClass':'addClass'](this.className('jcarousel-next-disabled')).attr('disabled',n?false:true);this.buttonPrev[p?'bind':'unbind'](this.options.buttonPrevEvent+'.jcarousel',this.funcPrev)[p?'removeClass':'addClass'](this.className('jcarousel-prev-disabled')).attr('disabled',p?false:true);if(this.buttonNext.length>0&&(this.buttonNext[0].jcarouselstate==undefined||this.buttonNext[0].jcarouselstate!=n)&&this.options.buttonNextCallback!=null){this.buttonNext.each(function(){self.options.buttonNextCallback(self,this,n);});this.buttonNext[0].jcarouselstate=n;}if(this.buttonPrev.length>0&&(this.buttonPrev[0].jcarouselstate==undefined||this.buttonPrev[0].jcarouselstate!=p)&&this.options.buttonPrevCallback!=null){this.buttonPrev.each(function(){self.options.buttonPrevCallback(self,this,p);});this.buttonPrev[0].jcarouselstate=p;}},notify:function(evt){var state=this.prevFirst==null?'init':(this.prevFirst<this.first?'next':'prev');this.callback('itemLoadCallback',evt,state);if(this.prevFirst!==this.first){this.callback('itemFirstInCallback',evt,state,this.first);this.callback('itemFirstOutCallback',evt,state,this.prevFirst);}if(this.prevLast!==this.last){this.callback('itemLastInCallback',evt,state,this.last);this.callback('itemLastOutCallback',evt,state,this.prevLast);}this.callback('itemVisibleInCallback',evt,state,this.first,this.last,this.prevFirst,this.prevLast);this.callback('itemVisibleOutCallback',evt,state,this.prevFirst,this.prevLast,this.first,this.last);},callback:function(cb,evt,state,i1,i2,i3,i4){if(this.options[cb]==undefined||(typeof this.options[cb]!='object'&&evt!='onAfterAnimation'))return;var callback=typeof this.options[cb]=='object'?this.options[cb][evt]:this.options[cb];if(!$.isFunction(callback))return;var self=this;if(i1===undefined)callback(self,state,evt);else if(i2===undefined)this.get(i1).each(function(){callback(self,this,i1,state,evt);});else{for(var i=i1;i<=i2;i++)if(i!==null&&!(i>=i3&&i<=i4))this.get(i).each(function(){callback(self,this,i,state,evt);});}},create:function(i){return this.format('<li></li>',i);},format:function(e,i){var $e=$(e).addClass(this.className('jcarousel-item')).addClass(this.className('jcarousel-item-'+i)).css({'float':'left','list-style':'none'});$e.attr('jcarouselindex',i);return $e;},className:function(c){return c+' '+c+(!this.options.vertical?'-horizontal':'-vertical');},dimension:function(e,d){var el=e.jquery!=undefined?e[0]:e;var old=!this.options.vertical?el.offsetWidth+$jc.margin(el,'marginLeft')+$jc.margin(el,'marginRight'):el.offsetHeight+$jc.margin(el,'marginTop')+$jc.margin(el,'marginBottom');if(d==undefined||old==d)return old;var w=!this.options.vertical?d-$jc.margin(el,'marginLeft')-$jc.margin(el,'marginRight'):d-$jc.margin(el,'marginTop')-$jc.margin(el,'marginBottom');$(el).css(this.wh,w+'px');return this.dimension(el);},clipping:function(){return!this.options.vertical?this.clip[0].offsetWidth-$jc.intval(this.clip.css('borderLeftWidth'))-$jc.intval(this.clip.css('borderRightWidth')):this.clip[0].offsetHeight-$jc.intval(this.clip.css('borderTopWidth'))-$jc.intval(this.clip.css('borderBottomWidth'));},index:function(i,s){if(s==undefined)s=this.options.size;return Math.round((((i-1)/s)-Math.floor((i-1)/s))*s)+1;}});$jc.extend({defaults:function(d){return $.extend(defaults,d||{});},margin:function(e,p){if(!e)return 0;var el=e.jquery!=undefined?e[0]:e;if(p=='marginRight'&&$.browser.safari){var old={'display':'block','float':'none','width':'auto'},oWidth,oWidth2;$.swap(el,old,function(){oWidth=el.offsetWidth;});old['marginRight']=0;$.swap(el,old,function(){oWidth2=el.offsetWidth;});return oWidth2-oWidth;}return $jc.intval($.css(el,p));},intval:function(v){v=parseInt(v);return isNaN(v)?0:v;}});})(jQuery);

