// What to add to images on rollover so test.jpg would become test-on.jpg
var overSuffix = '-on'
// Add this class to images to have them roll over
var rolloverClass = 'on'


// Core Javascript
$(document).ready(function() {
	
	//$('.' + rolloverClass).each(alert('here'));

    // All the button rollovers - the rollover image must have an -on suffix and sit in the same folder as the normal state. eg   
    $('.' + rolloverClass).hover(
	    function ()	{	
			//alert('here');
		    $(this).attr('src',doOverImg($(this).attr('src')))
	    },	
	    function ()	{	
		    $(this).attr('src',doDefaultImg($(this).attr('src')))
	    }
    )
		
	// Lower Nav set classes
	$('#nav-lower li:nth-child(1)').addClass("level0-1");
	$('#nav-lower li:nth-child(2)').addClass("level0-2");
	$('#nav-lower li:nth-child(3)').addClass("level0-3");
	$('#nav-lower li:nth-child(4)').addClass("level0-4");
	$('#nav-lower li:nth-child(5)').addClass("level0-5");
	$('#nav-lower li:nth-child(6)').addClass("level0-6");
	$('#nav-lower li:nth-child(7)').addClass("level0-7");
	$('#nav-lower li:nth-child(8)').addClass("level0-8");
	$('#nav-lower li:nth-child(9)').addClass("level0-9");
	$('#nav-lower li:nth-child(10)').addClass("level0-10");
	$('#nav-lower li:nth-child(11)').addClass("level0-11");
	$('#nav-lower li:nth-child(12)').addClass("level0-12");

	// Main Nav set classes
	$('#nav-main li:nth-child(1)').addClass("level0-1");
	$('#nav-main li:nth-child(2)').addClass("level0-2");
	$('#nav-main li:nth-child(3)').addClass("level0-3");
	$('#nav-main li:nth-child(4)').addClass("level0-4");
	$('#nav-main li:nth-child(5)').addClass("level0-5");
	$('#nav-main li:nth-child(6)').addClass("level0-6");
	$('#nav-main li:nth-child(7)').addClass("level0-7");
	$('#nav-main li:nth-child(8)').addClass("level0-8");
	$('#nav-main li:nth-child(9)').addClass("level0-9");
	$('#nav-main li:nth-child(10)').addClass("level0-10");
	$('#nav-main li:nth-child(11)').addClass("level0-11");
	$('#nav-main li:nth-child(12)').addClass("level0-12");

	$("ul.ui-tabs-nav > li").SelectedNav();
	
	$('#nav-top li:not(:last), #nav-account li:not(:last), #nav-footer li:not(:last), #other li:not(:last), #page-account #pane-1 li:not(:last)').append("&nbsp;|");        // , .tr-result td li:not(:last)    - C2 I took this out as it breaking the jobs listings
	$('#breadcrumbs li:not(:last)').append("&nbsp;>");
	$('#nav-main li:last, #nav-lower li li:last, #nav-lower li:last, #nav-channel li:last, #connect li:last, .news-item:last').addClass("last");
	$('#nav-main li:first, #nav-lower ul li:first').addClass("first");
	$('.puff-account, .puff-side, .puff-advert, .news').append('<span class="shadow">&nbsp;</span>');
	
	$('.case.captionfull').hover(function(){  
		 $(".cover", this).stop().animate({opacity:'1'},{queue:false,duration:160});  
	}, function() {  
		 $(".cover", this).stop().animate({opacity:'0'},{queue:false,duration:160});  
	}); 
	

	//$('#featured-content').tabs();
	//$('#employer-tabs').tabs();
	//$('#account-tabs').tabs();
	
	$('#search-options').hide();
	
	$("#qck-job-search h2 a").toggle(function(){
		$("#qck-job-search").toggleClass("open");
		$('#search-options').show();
		//$("#qck-job-search h2 a").css("color","#e66401");
    }, 
	function () {
        $('#search-options').hide();
		$("#qck-job-search").toggleClass("open");
		//return false;
	});
	
	
	
	// Set value of fields
	$("#frm-search input[type='text']").attr("value", "Search");
	var text = "Search";
	
		$("#frm-search input[type='text']").focus(function() {
			if($(this).attr("value") == text) $(this).attr("value", "");
		});
	
		$("#frm-search input[type='text']").blur(function() {
			if($(this).attr("value") == "") $(this).attr("value", text);
		});
});



// Roll over helpers
function doOverImg(path)	{
	start = path.substring(0, path.indexOf('.'))
	end = path.substring(path.indexOf('.'))
	overpath = (start + overSuffix + end);
	return overpath
}
function doDefaultImg(path)	{
	return path.replace(overSuffix,'');
}

(function($) {
    $.fn.SelectedNav = function(options) {

        options = $.extend({
            position: 0 // this sets the position of the 'home' nav option. If no matches are found, we highlight the anchor at this index.
        });

        var curUrl = window.location.href;


        this.each(function() {

            var cur = $(this), // current  LI
                i = $("a", cur), // anchor in LI
                href = i.attr("href"); // href of anchor

            if (href != "/") { //if the href isn't for the home page

                $("ul > li > a", cur).each(function() { // loop to check for child nodes for
                    if (CheckURL($(this))) { //if we have a match...
                        AddClass(i); //add the class
                        return false; // exit the each statement
                    }

                });
                if (CheckURL(i)) { //if we still haven't got a match check the normal non child nodes
                    AddClass(i);
                    return false;
                }

            }
        });

        if ($("ul > li > a.selected", this).size() == 0) { // if we STILL don't have a match, add it to the position as specified by the options (eg home page)
            $(this).eq(options.position).first().addClass("selected");
        }

        function CheckURL(a) {
            if (curUrl.indexOf(a.attr("href")) > 0) {
                return true;
            }

            return false;
        }

        function AddClass(a) {
            a.first().addClass("selected");
            
        }
    }
})(jQuery);


function changeSize(size){
	
	var arr = new Array();
	arr = document.getElementsByTagName("HTML");
	var ele = arr[0];
	
	var theDate = new Date();
	var oneYearLater = new Date( theDate.getTime() + 8640000 );
	var expiryDate = oneYearLater.toGMTString();
	
	document.cookie = 'pagesize='+size+'; expires='+expiryDate+'; path=/'

	
	if(size=="large"){
			ele.style.fontSize = "75%";
	}
	else if(size=="medium"){
			ele.style.fontSize = "70%";
	}
	else if(size=="small"){
			ele.style.fontSize = "62.5%";
	}
	
}
