/*
	Template Name: Structure v3.0
*/

var $j = jQuery.noConflict();
$j(document).ready(function() {
														
								
								
/* Set logo to fixed */
	jQuery('#logo-float').css('position', 'fixed');


	/* ------------------------------------------------
	   Initialize anchor scroll
	------------------------------------------------ */
	jQuery.localScroll({
		offset: -98,
		speed:2000
	});

	/* ------------------------------------------------
	   Initialize AJAX Contact Form
	------------------------------------------------ */
	jQuery('#contact-form').cepreuAjaxContactForm({
		ajax_error_msg:  '<span class="success-text"><p><span style="font-size:25px;">FAIL.</span><br /> Sorry, but an internal error has occurred. Your lack of success is probably the fault of the site and has nothing to do with you as a person... So relax and take a second to check out this video of a dog that is probably my dog, Ralph.<br /> Then try again, or hit me up via means listed out to your left. <iframe class="pad-top" title="YouTube video player" width="450" height="275" src="http://www.youtube.com/embed/JnjLb-egK7I" frameborder="0"></iframe></p></span>', // You can change these messages if you like
		ajax_success_msg: '<span class="success-text"><p><span style="font-size:25px;">Success!</span><br /> While you wait for a reply, take a second to check out this video of a dog that is probably my dog, Ralph. <iframe class="pad-top" title="YouTube video player" width="450" height="275" src="http://www.youtube.com/embed/JnjLb-egK7I" frameborder="0"></iframe></p></span>', // ...
		php_script: 'ajax-functions.php'
	});

});



/* ------------------------------------------------
   AJAX Contact Form with validation
------------------------------------------------ */
(function($) {
$.fn.cepreuAjaxContactForm = function(options) {

	// Default options
	options = $.extend({
		ajax_error_msg: '<span class="success-text"><p><span style="font-size:25px;">FAIL.</span><br /> Sorry, but an internal error has occurred. Your lack of success is probably the fault of the site and has nothing to do with you as a person... So relax and take a second to check out this video of a dog that is probably my dog, Ralph.<br /> Then try again, or hit me up via means listed out to your left. <iframe class="pad-top" title="YouTube video player" width="450" height="275" src="http://www.youtube.com/embed/JnjLb-egK7I" frameborder="0"></iframe></p></span>',
		ajax_success_msg: '<span class="success-text"><p><span style="font-size:25px;">Success!</span><br /> While you wait for a reply, take a second to check out this video of a dog that is probably my dog, Ralph. <iframe class="pad-top" title="YouTube video player" width="450" height="275" src="http://www.youtube.com/embed/JnjLb-egK7I" frameborder="0"></iframe></p></span>',
		php_script: 'http://buddesigns.com/TEMP/html/ajax-functions.php'
	}, options);

	var $target = $(this);

	var $name = $('#name');
	var $email = $('#email');
	var $subject  = $('#subject');
	var $message = $('#message');

	$target.validate({
		debug: false,
		event: 'submit',
			rules: {
				name: { required: true },
				email: {
					required: true,
					email: true,
					rangelength: [7,50]
				},
				subject: { required: true },
				message: {
					required: true,
					rangelength: [10,2000]
				}
			},
			messages: {
				name: { required: 'Please enter your name.' },
				email: {
					required: 'Please enter an email address.',
					email: 'This is not a valid e-mail address.'
				},
				subject: { required: 'Please enter an email subject.' },
				message: { required: 'Please enter your message.' }
			},

		errorPlacement: function(error, element) {
			error.insertAfter( element.parent('li').find('label') );
		},

		submitHandler: function() {

			$.ajax({
				type: 'POST',
				url: options.php_script,
				data: 'name=' + $name.val() + '&email=' + $email.val() + '&subject=' + $subject.val() + '&message=' + $message.val(),
				success: function(response) {
					if( response == 'ok' ) {
						$name.val('');
						$email.val('');
						$subject.val('');
						$message.val('');
						$target.parent().html(options.ajax_success_msg).hide().fadeIn(1000)
					} else {
						$name.val('');
						$email.val('');
						$subject.val('');
						$message.val('');
						$target.parent().html(options.ajax_error_msg).hide().fadeIn(1000)
					}
				}
			})
		}
	});

};
})(jQuery);

/* PORTFOLIO SLIDER */

$j(function($){
  var currentPosition = 0;
  var slideWidth = 680;
  var slides = $j('.slide');
  var numberOfSlides = slides.length;

  // Remove scrollbar in JS
  $j('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $j('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  $j('#slideshow')
    .prepend('<span class="control" id="leftControl">Clicking moves left</span>')
    .append('<span class="control" id="rightControl">Clicking moves right</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $j('.control')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($j(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $j('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $j('#leftControl').hide() } else{ $j('#leftControl').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $j('#rightControl').hide() } else{ $j('#rightControl').show() }
  }	
});(jQuery);

/* End Slider*/




/*
 * jQuery Reveal Plugin 1.0
 * www.ZURB.com
 * Copyright 2010, ZURB
 * Free to use under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
*/


(function($) {

/*---------------------------
 Defaults for Reveal
----------------------------*/
	 
/*---------------------------
 Listener for data-reveal-id attributes
----------------------------*/

	$('a[data-reveal-id]').live('click', function(e) {
		e.preventDefault();
		var modalLocation = $(this).attr('data-reveal-id');
		$('#'+modalLocation).reveal($(this).data());
	});

/*---------------------------
 Extend and Execute
----------------------------*/

    $.fn.reveal = function(options) {
        
        
        var defaults = {  
	    	animation: 'fadeAndPop', //fade, fadeAndPop, none
		    animationspeed: 500, //how fast animtions are
		    closeonbackgroundclick: true, //if you click background will modal close?
		    dismissmodalclass: 'close-reveal-modal' //the class of a button or element that will close an open modal
    	}; 
    	
        //Extend dem' options
        var options = $.extend({}, defaults, options); 
	
        return this.each(function() {
        
/*---------------------------
 Global Variables
----------------------------*/
        	var modal = $(this),
        		topMeasure  = parseInt(modal.css('top')),
				topOffset = modal.height() + topMeasure,
          		locked = false,
				modalBG = $('.reveal-modal-bg');

/*---------------------------
 Create Modal BG
----------------------------*/
			if(modalBG.length == 0) {
				modalBG = $('<div class="reveal-modal-bg" />').insertAfter(modal);
			}		    
        	
/*---------------------------
 Open and add Closing Listeners
----------------------------*/
        	//Open Modal Immediately
    		openModal();
			
			//Close Modal Listeners
			var closeButton = $('.' + options.dismissmodalclass).bind('click.modalEvent',closeModal)
			if(options.closeonbackgroundclick) {
				modalBG.css({"cursor":"pointer"})
				modalBG.bind('click.modalEvent',closeModal)
			}
			
    		
/*---------------------------
 Open & Close Animations
----------------------------*/
			//Entrance Animations
			function openModal() {
				embeds = document.getElementsByTagName('swfobject');
				for(i = 0; i < embeds.length; i++) {
    			embeds[i].style.visibility = 'hidden';
				}
				modalBG.unbind('click.modalEvent');
				$('.' + options.dismissmodalclass).unbind('click.modalEvent');
				if(!locked) {
					lockModal();
					if(options.animation == "fadeAndPop") {
						modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible'});
						modalBG.fadeIn(options.animationspeed/2);
						modal.delay(options.animationspeed/2).animate({
							"top": $(document).scrollTop()+topMeasure,
							"opacity" : 1
						}, options.animationspeed,unlockModal());					
					}
					if(options.animation == "fade") {
						modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+topMeasure});
						modalBG.fadeIn(options.animationspeed/2);
						modal.delay(options.animationspeed/2).animate({
							"opacity" : 1
						}, options.animationspeed,unlockModal());					
					} 
					if(options.animation == "none") {
						modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
						modalBG.css({"display":"block"});	
						unlockModal()				
					}   
				}
			}    	
			
			//Closing Animation
			function closeModal() {
				embeds = document.getElementsByTagName('swfobject');
				for(i = 0; i < embeds.length; i++) {
  				embeds[i].style.visibility = 'visible';
				}
				if(!locked) {
					lockModal();
					if(options.animation == "fadeAndPop") {
						modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
						modal.animate({
							"top":  $(document).scrollTop()-topOffset,
							"opacity" : 0
						}, options.animationspeed/2, function() {
							modal.css({'top':topMeasure, 'opacity' : 1, 'visibility' : 'hidden'});
							unlockModal();
						});					
					}  	
					if(options.animation == "fade") {
						modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
						modal.animate({
							"opacity" : 0
						}, options.animationspeed, function() {
							modal.css({'opacity' : 1, 'visibility' : 'hidden', 'top' : topMeasure});
							unlockModal();
						});					
					}  	
					if(options.animation == "none") {
						modal.css({'visibility' : 'hidden', 'top' : topMeasure});
						modalBG.css({'display' : 'none'});	
					}   			
				}
			}
			
/*---------------------------
 Animations Locks
----------------------------*/
			function unlockModal() { 
				locked = false;
			}
			function lockModal() {
				locked = true;
			}	
			
        });//each call
    }//orbit plugin call
})(jQuery);
        

/*LAZY LOAD
      $j(function() {          
          $j('img:not(.notlazy)').lazyload({
             placeholder : "images/grey.gif",
             effect      : "fadeIn"
          });
		
      });
 */
