var Layout = {

	navRendered: false,

	//Render NAV dropdowns
	renderNav: function() {

		if (!this.navRendered) {
			this.navRendered = true;
		}else{
			return;
		}

		var round = true;
		//I know it's deprecated.. but I just need to know if this is IE7.
		if (jQuery.browser.msie && jQuery.browser.version=='7.0') {
			round = false;
		}

		$('#nav ul li').each(function() {
			$(this).mouseenter(function() {
				$(this).children('ul').show();
				$(this).children('a').addClass('hover');
				if (round) $(this).children('ul').siblings('a').corner('bottom 1px');
			}).mouseleave(function() {
				$(this).children('ul').hide();
				$(this).children('a').removeClass('hover');
				if (round) $(this).children('ul').siblings('a').corner('bottom 5px');
			});
		});

		if (round) $('#nav ul li a').corner("5px");
		$('#nav ul li ul').siblings('a').corner('bottom 1px');
		$('#nav ul li ul li a').uncorner();
		$('#nav ul li ul').corner('bottom 5px');
		if (round) $('#nav ul li a.selected').corner("5px");

		//subnav
		$('#subnav ul li a').corner("5px");

		$('#subnav ul li a.selected').parent().append('<div class="arrow"></div>');

		$('.home-testi-balloon').corner("5px");
	},

	//Round the corners of boxes
	renderBox: function() {
		$('.box').corner('6px');
		$('.box h2').corner('top 6px');

		//What's next box
		if ($.browser.msie ) {
			//this is a fix applies to IE.
			$('.what').corner('bottom cc:#ECFCE2');
			$('#testi-box h2').corner('top 6px');
		} else {
			$('.what').corner('bottom');
			$('#testi-box h2').corner('top 6px');
		}
	},

	//Render the showreel
//	renderShowReel: function() {

		//Stop this function if the slider not found
//		if (document.getElementById('slider') == null) return;
//		$('#slider')
//		.before('<div id="slider-nav">')
//		.cycle({
//			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
//			pager: '#slider-nav',
//			timeout: 6000
//		});
//	},

	//Render the showreel - for testimonial
	renderShowReel: function() {

		//Stop this function if the slider not found
		if (document.getElementById('testimonial-slider') == null) return;

		var sliderHeight = $('#testimonial-slider').height();
		$('.home-testi-balloon').each(function(i, balloon) {
			var balloonHeight = $(balloon).outerHeight() + 20;
			if (balloonHeight > sliderHeight) {
				$(balloon).parent().remove();
			}
		});

		$('#testimonial-slider').css('visibility', 'visible');

        $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
                $(pager).find('img').removeClass('activeLI').attr('src', contextPath + '/img/icons/slider-nav-inactive.png')
                    .filter('img:eq('+currSlideIndex+')').addClass('activeLI').attr('src', contextPath + '/img/icons/slider-nav-active.png');
            };

		$('#testimonial-slider')
		.after('<div id="testimonial-slider-nav">')
		.cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			pager: '#testimonial-slider-nav',
			timeout: 120000,
            cleartypeNoBg: true,

            pagerAnchorBuilder: function(idx, slide) {
                return '<a href="#"><img src="' + contextPath + '/img/icons/slider-nav-inactive.png" width="16" height="16" /></a>';
            }
		});
	},

	//Render the showreel - for testimonial - one-click homepage
	renderShowReelForOneClick: function() {

		//Stop this function if the slider not found
		if (document.getElementById('testimonial-slider2') == null) return;
		$('#testimonial-slider2')
		.after('<div id="testimonial-slider-nav2">')
		.cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			pager: '#testimonial-slider-nav2',
			timeout: 120000
		});
	},

	renderVersionNumber: function() {

		$.get(contextPath + '/js/version.txt', function(data) {
			$('#build-info-number').html(data);
		});
	}
};

