//
//     JQuery Text resize + Cookie recall
//     by Jonny Kamaly
//     based on script written by Faisal &amp; Homar
//
 
 
$(document).ready(function(){
		// show text resizing links
		$(".FontSize").show();
		var $cookie_name = "sitename-FontSize";
		var originalFontSize = $("html").css("font-size");
		// if exists load saved value, otherwise store it
		if($.cookie($cookie_name)) {
			var $getSize = $.cookie($cookie_name);
			$("html").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
		} else {
			$.cookie($cookie_name, originalFontSize);
		}
		// reset link
		$(".FontSizeReset").bind("click", function() {
			$("html").css("font-size", originalFontSize);
			$.cookie($cookie_name, originalFontSize);
		});
		// text “+" link
		$(".FontSizeInc").bind("click", function() {
		  var currentFontSize = $("html").css("font-size");
		  var currentFontSizeNum = parseFloat(currentFontSize, 10);
		  var newFontSize = currentFontSizeNum*1.2;
		  if (newFontSize, 11) {
		    $("html").css("font-size", newFontSize);
		    $.cookie($cookie_name, newFontSize);
		  }
		  return false;
		});
		$(".FontSizeDec").bind("click", function() {
		  var currentFontSize = $("html").css("font-size");
		  var currentFontSizeNum = parseFloat(currentFontSize, 10);
		  var newFontSize = currentFontSizeNum*0.8;
		  if (newFontSize, 11) {
		    $("html").css("font-size", newFontSize);
		    $.cookie($cookie_name, newFontSize);
		  }
		  return false;
		});
});

//
// jQuery Placeholder plugin
//	by Alex Gisby
// 
// Quick little plugin for replicating the placeholder attribute in HTML5 for all browsers.
//
// This software is licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
//
// Enjoy!
//


jQuery.fn.placeholder = function()
{
	// Support bits: (thanks to Dive into HTML 5 (http://diveintohtml5.org/))
	var i = document.createElement('input');
	jQuery.support.placeholder = ('placeholder' in i);
	
	jQuery.each(this, function()
	{
		if(jQuery(this).attr('placeholder'))
		{
			if((jQuery(this).val() == '' && !jQuery.support.placeholder) || jQuery(this).val() == jQuery(this).attr('placeholder'))
			{
				if(!jQuery.support.placeholder){ jQuery(this).val(jQuery(this).attr('placeholder')); }
				jQuery(this).addClass('placeholder-active');
			}
			else if(jQuery.support.placeholder && jQuery(this).val() == '')
			{
				jQuery(this).addClass('placeholder-active');
			}
			
			jQuery(this).focus(function()
			{
				if(jQuery(this).val() == jQuery(this).attr('placeholder') || jQuery.support.placeholder)
				{
					if(!jQuery.support.placeholder){ $(this).val(''); }
					jQuery(this).removeClass('placeholder-active');
				}
			});
			
			jQuery(this).blur(function()
			{
				if(jQuery(this).val() == '')
				{
					if(!jQuery.support.placeholder){ jQuery(this).val(jQuery(this).attr('placeholder')); }
					jQuery(this).addClass('placeholder-active');
				}
			});
			
			// Go and add a submit callback for this form to erase the data
			jQuery(this).parents('form').bind('submit', { placeholderElement: jQuery(this) }, function(event)
			{
				var element = event.data.placeholderElement;
				if(element.val() == element.attr('placeholder'))
				{
					element.val('');
				}
			});
		}
	});
}

$slideshow = {
    context: false,
    tabs: false,
    timeout: 5000,      // time before next slide appears (in ms)
    slideSpeed: 3000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'fade',   // the slide effect to use
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slideshow');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('ul.slides-nav li', this.context);
        
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
        
        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },
    
    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $('div.slides > ul', $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $('ul.slides-nav', $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });            
    },
    
    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
        
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');
            
            // add active styling to active button
            activeTab.parent().addClass('on');
        }            
    }            
};


$(function() {
    // add a 'js' class to the body
    $('body').addClass('js');
    
    // initialise the slideshow when the DOM is ready
    $slideshow.init();
});

$(document).ready(function(){
	$('input[type=text], textarea').placeholder();
	
	$('#servicesfooter li:last').css({"border" : "none"});
	$('#access li:last a').css({"background" : "none"});
	$('.submenu li:last a').css({"background" : "none"});
	$('.bottom-large-widget li:last.widget-container').css({"margin" : "0"});
});	
