
//	Cufon.replace('h1', {'fontSize': '28px', 'color': '#444'});
	Cufon.replace('h2', {'fontSize': '18px'});
	Cufon.replace('h3');
//	Cufon.replace('h4');
	Cufon.replace('.ActionTabsFont', {'fontSize': '16px'});
	Cufon.replace('.ccHead');
	Cufon.replace('.TabsFont');
	Cufon.replace('.overlay');
	Cufon.replace('#social_button', {'fontSize': '17px'});

// function for opening the social stuff



$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }

    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),


            singleWidth = $single.outerWidth(),
            visible = Math.round($wrapper.outerWidth() / singleWidth),
            currentPage = 1,
            pages = Math.round($items.length / visible);


		    

        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect

        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);

        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            

            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                }

                currentPage = page;
            });

            return false;
        }

        $wrapper.after('<a class="arrow back"></a><a class="arrow forward"></a>');

        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);
        });

        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });

        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
    });
};

//function ready methods required on every page
$(document).ready(function() {

    $('.nav').bnavigation();

    //isValidEmailAdress by http://www.reynoldsftw.com/2009/03/live-email-validation-with-jquery/
    function isValidEmailAddress(emailAddress) {
      var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
      return pattern.test(emailAddress);
    }

    // use jquery for form errors
    $('form#commentform').submit(function() {
		$('#commentsErrorWrapper .error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
            // check if field is empty
			if(jQuery.trim($(this).val()) == '') {
				var labelText = $('#commentField_'+$(this).attr('id')).text().replace('*', '');
				$('#commentsErrorWrapper').append('<p class="error">'+labelText+' is required </p><br class="clear" />');
				hasError = true;
			}
            //check for email error
            if(jQuery.trim($(this).attr('id')) == 'email') {
              if(!isValidEmailAddress(jQuery.trim($(this).val()))) {
                $('#commentsErrorWrapper').append('<p class="error">Email Address is not valid</p><br class="clear" />');
                hasError = true;
              }
            }
		});
		if(hasError) {
			return false;
		}
	});

    /* gallery effects */
	$('.gallery li ul').children().hide();
	$('.gallery li').hover(
		function () {
			$(this).find('img').stop().fadeTo(300, '0.6');
		},
		function () {
			$(this).find('img').stop().fadeTo('fast', '1.0');
		}
	);
    $('.portfolio-image').hover(
      function () {
          $(this).stop().fadeTo(300, '0.6');
      },
      function () {
          $(this).stop().fadeTo('fast', '1.0');
      }
    );
    $('.wrapper ul li').hover(
      function () {
          $(this).find('img').stop().fadeTo(300, '0.6');
      },
      function () {
          $(this).find('img').stop().fadeTo('fast', '1.0');
      }
    );

});
