/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
$(document).ready(function() { 
		
		$('#menuright').append('<div id="resize"><ul><li class="normal"><a class="normalsize" href="#" title="Normal text size">Normal text size</a></li><li class="large"><a href="#" class="largesize" title="Large text size">Large text size</a></li></ul></div>');
		
	if($.cookie('TEXT_SIZE')) {
  			$('#main').addClass($.cookie('TEXT_SIZE')); 
	}
 
 $('#resize a').click(function() {
  var textSize = $(this).parent().attr('class');
  $('#main').removeClass('small medium large').addClass(textSize);
  $.cookie('TEXT_SIZE',textSize, { path: '/', expires: 10000 });
  return false;
 });
					
	//Video View Slider
	
	var view_li = $(".galleryarea ul li").width();
	var view_li_sum = $(".galleryarea ul li").size();
	var view_width = ( view_li + 10 ) * view_li_sum;

	$(".galleryarea").append('<a href="#older" class="older">Older</a>')
	$(".galleryarea").prepend('<a href="#newer" class="newer">Newer</a>')
	$(".gallerymask").removeClass('gallerymask').addClass('galleryjs');
	
	$(".galleryarea ul").css({'width' : view_width}).addClass('galleryjs');
	
	var imageurl = $('.galleryarea ul').find('img').attr('src');
	var imagealt = $('.galleryarea ul').find('img').attr('alt');
		
	$(".galleryarea ul").parent().parent().prepend('<h2 class="desc">'+ imagealt +'</h2><img src="'+ imageurl +'" alt="'+ imagealt +'" class="jsimage" />');
	
	//Click image function 
	
	$(".galleryarea ul img").click(function() {	
		var newsrc = $(this).attr('src');
		var newalt = $(this).attr('alt');
		$(this).parent().parent().parent().parent().find('.desc').remove();
		$(this).parent().parent().parent().parent().find('img:first').replaceWith('<img src="'+ newsrc +'" alt="'+ newalt +'" class="jsimage" />');
		$(this).parent().parent().parent().parent().prepend('<h2 class="desc">'+ newalt +'</h2>');
	});
	
	var sum = 0;
	
	$("a.older").click(function() {	
										   
		if(sum < ((view_li_sum)-2)) {		
			sum++;
		
			$(".galleryarea ul").animate({ marginLeft: "-="+((view_li) + 10) +"px"}, 700);
			$("a.newer").removeClass('disable');
			if (sum == view_li_sum) 
				{
					$(".viewer ul").stop();
					$(sum).stop();
				}
			if (sum == ((view_li_sum)-2)) 
				{
					$("a.older").addClass('disable');
					$("a.newer").removeClass('disable');
				}
		}
		return false;
		
	});
	
	$("a.newer").addClass('disable');
	$("a.newer").click(function() {
		if(sum > 0) {		
			sum--;
			
			$(".galleryarea ul").stop();	
			$(".galleryarea ul").animate({ marginLeft: "+=95px"}, 700);	
			$("a.older").removeClass('disable');
			if (sum == -1) 
				{
					$(".galleryarea ul").stop();	
					$("a.newer").addClass('disable');
				}
			if (sum == 0) 
				{
					$("a.newer").addClass('disable');
				}
		}
		return false;
	});
	
	$(".galleryarea ul li").hover(function() {
			$(this).addClass('active');	
		} , function() {
			$(this).removeClass('active');	  
	});
	
//Team show more function 
$("#corestaff li p").hide();
$("#corestaff li p").parent().append('<a href="#" class="showmore">More info...</a>');	
$("#corestaff li a.showmore").click(function(){
	$(this).parent().find('p').show();
	$(this).hide();
	return false;	
});

//Rounded corners in IE
  DD_roundies.addRule('#container, #primary, #menuright input[type="text"]', '30px', false);
  //DD_roundies.addRule('.galleryarea, .childpages li', '10px', false);

//Change US to UK wording
	$('.wpmem_reg input#zip').parent().prev().html('Postcode:<font color="red">*</font>');

	$('.wpmem_reg input#thestate').parent().prev().html('County:<font color="red">*</font>');
//.css('background','red')

});
