$(function(){
    $('#gallery a').lightBox();
    $('.lightbox').lightBox();
	$('#tabs').tabs();
    $("#irata-levels").accordion({ 
    	header: "h2",
    	active: false, 
        alwaysOpen: false
    });
    $("#subnav").accordion({ 
    	autoheight: false
    });
    processNews();
	processRollovers();
});

function processNews() {
	$('#news').hide();
	$.getJSON('/news/','',processNewsJSON);
	$('#news').fadeIn(3000); 
	$("#news").serialScroll({
		items:'a',
		duration:5000,
		force:true,
		axis:'y',
		easing:'linear',
		lazy:true,
		interval:1,
		step:1
	});
}

function processNewsJSON(data, textStatus) {
	var newsXHTML = '';
	$.each(data,function(title, field) {
		newsXHTML += '<div class="box-article">';
		newsXHTML += '	<div class="box-article-title"><a href="/news/' + field.url + '">' + field.title + '</a></div><div class="clear-left"></div>'; 
		newsXHTML += '	<div class="box-article-image"><img src="' + field.image + '" height="56" width="56" alt="' + field.title + '" /></div>';
		newsXHTML += '	<div class="box-article-article">' + field.summery + '</div>';
		newsXHTML += '</div>';
	});
	$('#news').html(newsXHTML);
}
 
function processRollovers() {
	$("#subnav .sellmore .book img").mouseenter(function() {
		$('#subnav .sellmore .book img').attr('src', '/images/booknow_small_selected.gif');
	});
	$("#subnav .sellmore .book img").mouseleave(function() {
		$('#subnav .sellmore .book img').attr('src', '/images/booknow_small.gif');
	});
	
	$("#subnav .sellmore .more img").mouseenter(function() {
		$('#subnav .sellmore .more img').attr('src', '/images/more_small_selected.gif');
	});
	$("#subnav .sellmore .more img").mouseleave(function() {
		$('#subnav .sellmore .more img').attr('src', '/images/more_small.gif');
	});

	$("#main-footer-contracting .moreinfo .more img").mouseenter(function() {
		$('#main-footer-contracting .moreinfo .more img').attr('src', '/images/more_small_selected.gif');
	});
	$("#main-footer-contracting .moreinfo .more img").mouseleave(function() {
		$('#main-footer-contracting .moreinfo .more img').attr('src', '/images/more_small.gif');
	});
	
	$("#main-footer-fallprotection .moreinfo .more img").mouseenter(function() {
		$('#main-footer-fallprotection .moreinfo .more img').attr('src', '/images/more_small_selected.gif');
	});
	$("#main-footer-fallprotection .moreinfo .more img").mouseleave(function() {
		$('#main-footer-fallprotection .moreinfo .more img').attr('src', '/images/more_small.gif');
	});
	
	$(".shopnow .shopnowbtn img").mouseenter(function() {
		$('.shopnow .shopnowbtn img').attr('src', '/images/shopnow_small_selected.gif');
	});
	$(".shopnow .shopnowbtn img").mouseleave(function() {
		$('.shopnow .shopnowbtn img').attr('src', '/images/shopnow_small.gif');
	});
	
	$("#training-irata .trainingmore img").mouseenter(function() {
		$('#training-irata .trainingmore img').attr('src', '/images/more_small_selected.gif');
	});
	$("#training-irata .trainingmore img").mouseleave(function() {
		$('#training-irata .trainingmore img').attr('src', '/images/more_small.gif');
	});
	
	$("#training-heightsafety .trainingmore img").mouseenter(function() {
		$('#training-heightsafety .trainingmore img').attr('src', '/images/more_small_selected.gif');
	});
	$("#training-heightsafety .trainingmore img").mouseleave(function() {
		$('#training-heightsafety .trainingmore img').attr('src', '/images/more_small.gif');
	});
	
	$("#training-rescue .trainingmore img").mouseenter(function() {
		$('#training-rescue .trainingmore img').attr('src', '/images/more_small_selected.gif');
	});
	$("#training-rescue .trainingmore img").mouseleave(function() {
		$('#training-rescue .trainingmore img').attr('src', '/images/more_small.gif');
	});
	
	$("#training-ladders .trainingmore img").mouseenter(function() {
		$('#training-ladders .trainingmore img').attr('src', '/images/more_small_selected.gif');
	});
	$("#training-ladders .trainingmore img").mouseleave(function() {
		$('#training-ladders .trainingmore img').attr('src', '/images/more_small.gif');
	});
	
	$("#training-heightsafetymanagment .trainingmore img").mouseenter(function() {
		$('#training-heightsafetymanagment .trainingmore img').attr('src', '/images/more_small_selected.gif');
	});
	$("#training-heightsafetymanagment .trainingmore img").mouseleave(function() {
		$('#training-heightsafetymanagment .trainingmore img').attr('src', '/images/more_small.gif');
	});
	
	
	$("#nav_item1").mouseenter(function() {
		$('#nav_item1').css('background-image', 'url(/images/nav_tab_green_selected.gif)');
		$('#nav_item1').append('<span id="indicator" class="nav-indicator ui-icon ui-icon-circle-arrow-e"/>');
		$("#nav_item1").click(function() {
			window.location="/training/";
		});
	});
	$("#nav_item1").mouseleave(function() {
		$('#indicator').remove();
		$('#nav_item1').css('background-image', 'url(/images/nav_tab_green1.png)');
	});

	$("#nav_item2").mouseenter(function() {
		$('#nav_item2').css('background-image', 'url(/images/nav_tab_green_selected.gif)');
		$('#nav_item2').append('<span id="indicator" class="nav-indicator ui-icon ui-icon-circle-arrow-e"/>');
		$("#nav_item2").click(function() {
			window.location="/contracting/";
		});
	});
	$("#nav_item2").mouseleave(function() {
		$('#indicator').remove();
		$('#nav_item2').css('background-image', 'url(/images/nav_tab_green2.png)');
	});
	
	$("#nav_item3").mouseenter(function() {
		$('#nav_item3').css('background-image', 'url(/images/nav_tab_green_selected.gif)');
		$('#nav_item3').append('<span id="indicator" class="nav-indicator ui-icon ui-icon-circle-arrow-e"/>');
		$("#nav_item3").click(function() {
			window.location="/fallprotection/";
		});
	});
	$("#nav_item3").mouseleave(function() {
		$('#indicator').remove();
		$('#nav_item3').css('background-image', 'url(/images/nav_tab_green3.png)');
	});
	
	$("#nav_item4").mouseenter(function() {
		$('#nav_item4').css('background-image', 'url(/images/nav_tab_green_selected.gif)');
		$('#nav_item4').append('<span id="indicator" class="nav-indicator ui-icon ui-icon-circle-arrow-e"/>');
		$("#nav_item4").click(function() {
			window.location="/consultancy/";
		});
	});
	$("#nav_item4").mouseleave(function() {
		$('#indicator').remove();
		$('#nav_item4').css('background-image', 'url(/images/nav_tab_green4.png)');
	});
	
	$("#nav_item5").mouseenter(function() {
		$('#nav_item5').css('background-image', 'url(/images/nav_tab_green_selected.gif)');
		$('#nav_item5').append('<span id="indicator" class="nav-indicator ui-icon ui-icon-circle-arrow-e"/>');
		$("#nav_item5").click(function() {
			window.location="/equipment/";
		});
	});
	$("#nav_item5").mouseleave(function() {
		$('#indicator').remove();
		$('#nav_item5').css('background-image', 'url(/images/nav_tab_green5.png)');
	});
	
	$("#nav_news").click(function() {
		window.location="/news/";
	});
}