$(document).ready(function() {
	
	var x = getCookie( 'increase' );
	//alert(x);
	if(x) {
		$("body").css({'font-size' : '1.49em'});
	} else {
		$("body").css({'font-size' : '1.3em'});
	}
	
	$("#decrease").bind("click", function(){
		$("body").css({'font-size' : '1.3em'});
		deleteCookie('increase', '/', '');
		
	});
	
	$("#increase").bind("click", function(){
		$("body").css({'font-size' : '1.49em'});
		setCookie('increase', 'done', 7, '/', '','');
	});
	
	
	$("#subForm input:image").click(function() {	
        
        // First, disable the form from submitting
        $('form#subForm').submit(function() { return false; });
        
        // Grab form action
        formAction = $("form#subForm").attr("action");
        
        // Hacking together id for email field
        // Replace the xxxxx below:
        // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
        emailId = "duddkr";
        emailId = emailId.replace("/", "");
        emailId = emailId + "-" + emailId;
        
        // Validate email address with regex
        if (!checkEmail(emailId)) 
        {
            alert("Please enter a valid email address");
            return;
        }
        
        // Serialize form values to be submitted with POST
        var str = $("form#subForm").serialize();
        
        // Add form action to end of serialized data
        finalForm = str + "&action=" + formAction;
        
        // Submit the form via ajax
        $.ajax({
            url: "proxy.php",
            type: "POST",
            data: finalForm,
            success: function(html){
                $("#theForm").hide(); // If successfully submitted hides the form
                $("#confirmation").slideDown("slow");  // Shows "Thankyou for subscribing." div
            }
        });
    });
    
    $("#careerForm input:image").click(function() {	
        
        // First, disable the form from submitting
        $('form#careerForm').submit(function() { return false; });
        
        // Grab form action
        formAction = $("form#careerForm").attr("action");
        
        // Hacking together id for email field
        // Replace the xxxxx below:
        // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
        emailId = "duddkl";
        emailId = emailId.replace("/", "");
        emailId = emailId + "-" + emailId;
        
        // Validate email address with regex
        if (!checkEmail(emailId)) 
        {
            alert("Please enter a valid email address");
            return;
        }
        
        // Serialize form values to be submitted with POST
        var str = $("form#careerForm").serialize();
        
        // Add form action to end of serialized data
        finalForm = str + "&action=" + formAction;
        
        // Submit the form via ajax
        $.ajax({
            url: "proxy.php",
            type: "POST",
            data: finalForm,
            success: function(html){
                $("#theForm").hide(); // If successfully submitted hides the form
                $("#confirmation").slideDown("slow");  // Shows "Thankyou for subscribing." div
            }
        });
    });


	//carousel


	if($("#slides").length) {

		/*

			<li class="">
				<a href="#0">1</a>
			</li>
			<li class="current">
				<a href="#1">2</a>
			</li>
			<li class="">
				<a href="#2">3</a>
			</li>
		</ul>
		*/


		var $pagination = $('#slides .pagination'),
			$slideContainer  = $('.slides_container'),
			$container = $('.slides_container .container'),
			zIndex = 0,
			paginationHtml = '',
			paginationWidth = 0,
			i = 0,
			$slideArray = [],
			currentIndex = -1,
			timer,
			firstTime = true

		$('.slide').each(function(index){

			$slideArray.push($(this));

			$(this).css({
				'left': 530
			});

			paginationHtml += '<li><a href="#'+index+'">'+index+'</a></li>'
			paginationWidth += 18;

		});
		
		$prevClip = $slideArray[$slideArray.length-1]
		$pagination.append(paginationHtml);
		$pagination.css({'z-index':9999})
		
		var $paginationItem = $pagination.find('a')

		$paginationItem.each(function(index){
			
			$(this).data('enabled',true)

			$(this).click(function(e){
				if($(this).data('enabled')){
					gotoSlide(index);
				}
				e.preventDefault()
			})
		});

		$slideContainer.css({display:'block'});

		$slideContainer.hide();

		$slideContainer.fadeIn();


		var paginationOffset = ($slideContainer.width() - paginationWidth)/2

		$pagination.css({left:paginationOffset});

		
	

		function loopSlides(){

			
			
			currentIndex ++
			if(currentIndex > $paginationItem.length-1){
				currentIndex = 0
			}
			gotoSlide(currentIndex);
			

		}

		function gotoSlide(index){
			var offsetX = -eval($slideArray[index].css('left').split('px').join(''))
			
			$slideArray[index].css({left:530+'px', 'z-index':zIndex, 'background-color':'#ffffff'})
			$slideArray[index].stop(true,true).animate({'left':0 + 'px'}, 500)
			
			if(!firstTime){
			$prevClip.stop(true,true).animate({'left':-530 + 'px'}, 500)
			}
			$pagination.css({'z-index':zIndex+4})
			
			$paginationItem.each(function(pIndex){

				if(pIndex == index){
					$(this).data('enabled',false)
					$(this).parent().addClass('current')
				}else{
					$(this).data('enabled',true)
					$(this).parent().removeClass('current')
				}

			});
			zIndex++

			clearInterval(timer);

			timer = setInterval(loopSlides,7000);

			currentIndex = index;
			
			$prevClip = $slideArray[index]
			
			firstTime = false
			

		}
		
	
			loopSlides()

	}
		
});

function checkEmail(email)
{	
    var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var emailVal = $("#" + email).val();
    return pattern.test(emailVal);
}

function getCookie( name ) {
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
    return null;
  }
  if ( start == -1 ) return null;
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie = name+"="+escape( value ) +
    ( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
  if ( getCookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



///* Text changer - light version.
//Let your text's font size customizable.
//by Marco Rosella - http://www.centralscrutinizer.it/en/design/js-php/text-changer
//                v0.2 - May 18, 2006
//*/
//function initFontResize()
//{
//	textChanger.init();
//}
//var textChanger = {
//	defaultFS : 1,
//	init: function()
//	{
//		var el = document.getElementsByTagName("body")[0];
//		var sz = textChanger.getCookie();
//		el.style.fontSize = sz ? sz + 'em' : textChanger.defaultFS + 'em';
//		var incr = document.getElementById('increase');
//		if(incr)
//			incr.onclick = function(){textChanger.changeSize(1); return false;};
//		var decr = document.getElementById('decrease');
//		if(decr)
//			decr.onclick = function(){textChanger.changeSize(-1); return false;};
//		var reset = document.getElementById('reset');
//		if(reset)
//			reset.onclick = function(){textChanger.changeSize(0); return false;};
//	},
//	changeSize: function(val)
//	{
//		var el = document.getElementsByTagName("body")[0];
//		var size = el.style.fontSize.substring(0,3);
//		var fSize = parseFloat(size,10);
//		if (val == 1)
//		{
//			fSize += 0.11;
//			if (fSize > 2.0) fSize = 2.0;
//		} 
//		if (val == -1)
//		{
//			fSize -= 0.11;
//			if (fSize < 0.5) fSize = 0.5;
//		}       
//		if (val == 0)
//		{
//			fSize = 1;
//		}
//		el.style.fontSize = fSize + 'em';
//		textChanger.updateCookie(fSize);
//	},
//	updateCookie: function(vl)
//	{
//		var today = new Date();
//		var exp = new Date(today.getTime() + (365*24*60*60*1000));
//		document.cookie = 'textChangerL=size=' + vl + ';' +'expires=' + exp.toGMTString() + ';' +'path=/';
//	},
//	getCookie: function()
//	{ 
//		var cname = 'textChangerL=size=';   
//		var start = document.cookie.indexOf(cname);
//		var len = start + cname.length;
//		if ((!start) && (cname != document.cookie.substring(0,cname.length))) {return null;}
//		if (start == -1) return null;
//		var end = document.cookie.indexOf(";",len);
//		if (end == -1) end = document.cookie.length;
//		return unescape(document.cookie.substring(len, end));
//	}
//}
//if (window.addEventListener)
//	window.addEventListener("load", initFontResize, false);
//else if (window.attachEvent && !window.opera)
//	window.attachEvent("onload", initFontResize);



