/* Lighbox */
$(function() {
	$('.gallery a').lightBox({fixedNavigation:true});
});




/*////////////////////////////////////////////////////////////////
/
/				 V I D E O   T A B S 
/
////////////////////////////////////////////////////////////////*/


	
		$(document).ready(function() {
		 
		    //Default Action
		    $(".tab_content").hide(); //Hide all content
		    $(".tab_content:first").show(); //Show first tab content
		    
		    //On Click Event
		    $("ul.tabs li").click(function() {
		    	$(".tab_content").hide(); //Hide all tab content
		    	var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		    	$(activeTab).fadeIn(); //Fade in the active content
		    	return false;
		    });
		 
		});
		
		
		




/*////////////////////////////////////////////////////////////////
/
/				 N I V O  S L I D E R
/
////////////////////////////////////////////////////////////////*/

    		$(window).load(function() {
    		    $('#slider').nivoSlider({
    		    	effect: 'fade',
    		    	pauseTime: 4500,
    		    });
    		});
    		
    		
    		

/*////////////////////////////////////////////////////////////////
/
/				 F O R M  V A L I D A T O R
/
////////////////////////////////////////////////////////////////*/


/*
Created 09/27/09										
Questions/Comments: jorenrapini@gmail.com						
COPYRIGHT NOTICE		
Copyright 2009 Joren Rapini
*/

	

$(document).ready(function(){
	// Place ID's of all required fields here.
	required = ["FormValue_CustomField1", "FormValue_EmailAddress"];
	// If using an ID other than #email or #error then replace it here
	email = $("#FormValue_EmailAddress");
	errornotice = $(".error");
	// The text to show up within a field when it is incorrect
	emptyerror = "Please fill out this field.";
	emailerror = "Please enter a valid e-mail.";

	$("#theform").submit(function(){	
		//Validate required fields
		for (i=0;i<required.length;i++) {
			var input = $('#'+required[i]);
			if ((input.val() == "") || (input.val() == emptyerror)) {
				input.addClass("needsfilled");
				input.val(emptyerror);
				errornotice.fadeIn(750);
			} else {
				input.removeClass("needsfilled");
			}
		}
		// Validate the e-mail.
		if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
			email.addClass("needsfilled");
			email.val(emailerror);
		}

		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if ($(":input").hasClass("needsfilled")) {
			return false;
		} else {
			errornotice.hide();
			return true;
		}
	});
	
	// Clears any fields in the form when the user clicks on them
	$(":input").focus(function(){		
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
			$(this).removeClass("needsfilled");
	   }
	});
});	



/*////////////////////////////////////////////////////////////////
/
/				 P L A C E  H O L D E R  F A L L B A C K (Forms)
/
////////////////////////////////////////////////////////////////*/

 $(function setupPlaceholder(inputid) {
    if ($.browser.webkit) return false;
 
    var target = $('#'+inputid);
    if (target.length==0) {
        target = $('input[type="text"], input[type="email"], input[type="search"]');
    }
 
    target.each( function(i, el) {
        el = $(el);
        var ph = el.attr('placeholder');
        if (!ph) return true;
 
        el.addClass('placeholder');
        el.attr('value', ph);
 
        el.focus( function(e) {
            if( el.val()==ph ) {
                el.removeClass('placeholder');
                el.attr('value', '');
            }
        });
 
        el.blur( function(e) {
            if( $.trim(el.val())=='' ) {
                el.addClass('placeholder');
                el.attr('value', ph);
            }
        });
    });
});	

/*////////////////////////////////////////////////////////////////
/
/				Q U O T A T O R - Testimonials 
/
////////////////////////////////////////////////////////////////*/
		
		
		$(document).ready(function(){
		    $('#testimonials .slide');
		    setInterval(function(){
		    	$('#testimonials .slide').filter(':visible').fadeOut(1000,function(){
		    		if($(this).next('li.slide').size()){
		    			$(this).next().fadeIn(1000);
		    		}
		    		else{
		    			$('#testimonials .slide').eq(0).fadeIn(1000);
		    		}
		    	});
		    },10000);	
		});	
  



/*////////////////////////////////////////////////////////////////
/
/				 TOOL TIPS 
/
////////////////////////////////////////////////////////////////*/



$(document).ready(function() {
    //Tooltips
    $(".tip_trigger").hover(function(){
        tip = $(this).find('.tip');
        tip.show(); //Show tooltip
    }, function() {
        tip.hide(); //Hide tooltip
    }).mousemove(function(e) {
        var mousex = e.pageX + 20; //Get X coodrinates
        var mousey = e.pageY + 20; //Get Y coordinates
        var tipWidth = tip.width(); //Find width of tooltip
        var tipHeight = tip.height(); //Find height of tooltip

        //Distance of element from the right edge of viewport
        var tipVisX = $(window).width() - (mousex + tipWidth);
        //Distance of element from the bottom of viewport
        var tipVisY = $(window).height() - (mousey + tipHeight);

        if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
            mousex = e.pageX - tipWidth - 20;
        } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
            mousey = e.pageY - tipHeight - 20;
        }
        //Absolute position the tooltip according to mouse position
        tip.css({  top: mousey, left: mousex });
    });
});





/*////////////////////////////////////////////////////////////////
/
/				 H T M L  R E P L A C E 
/
////////////////////////////////////////////////////////////////*/

	
function accentsToHtml($string)
{
    $string = str_replace("À", "&Agrave;", $string);
    $string = str_replace("Á", "&Aacute;", $string);
    $string = str_replace("Â", "&Acirc;", $string);
    $string = str_replace("Ã", "&Atilde;", $string);
    $string = str_replace("Ä", "&Auml;", $string);
    $string = str_replace("Å", "&Aring;", $string);
    $string = str_replace("Æ", "&Aelig;", $string);
    $string = str_replace("à", "&agrave;", $string);
    $string = str_replace("á", "&aacute;", $string);
    $string = str_replace("â", "&acirc;", $string);
    $string = str_replace("ã", "&atilde;", $string);
    $string = str_replace("ä", "&auml;", $string);
    $string = str_replace("å", "&aring;", $string);
    $string = str_replace("æ", "&aelig;", $string);
    $string = str_replace("Ç", "&Ccedil;", $string);
    $string = str_replace("ç", "&ccedil;", $string);
    $string = str_replace("Ð", "&ETH;", $string);
    $string = str_replace("ð", "&eth;", $string);
    $string = str_replace("È", "&Egrave;", $string);
    $string = str_replace("É", "&Eacute;", $string);
    $string = str_replace("Ê", "&Ecirc;", $string);
    $string = str_replace("Ë", "&Euml;", $string);
    $string = str_replace("è", "&egrave;", $string);
    $string = str_replace("é", "&eacute;", $string);
    $string = str_replace("ê", "&ecirc;", $string);
    $string = str_replace("ë", "&euml;", $string);
    $string = str_replace("Ì", "&Igrave;", $string);
    $string = str_replace("Í", "&Iacute;", $string);
    $string = str_replace("Î", "&Icirc;", $string);
    $string = str_replace("Ï", "&Iuml;", $string);
    $string = str_replace("ì", "&igrave;", $string);
    $string = str_replace("í", "&iacute;", $string);
    $string = str_replace("î", "&icirc;", $string);
    $string = str_replace("ï", "&iuml;", $string);
    $string = str_replace("Ñ", "&Ntilde;", $string);
    $string = str_replace("ñ", "&ntilde;", $string);
    $string = str_replace("Ò", "&Ograve;", $string);
    $string = str_replace("Ó", "&Oacute;", $string);
    $string = str_replace("Ô", "&Ocirc;", $string);
    $string = str_replace("Õ", "&Otilde;", $string);
    $string = str_replace("Ö", "&Ouml;", $string);
    $string = str_replace("Ø", "&Oslash;", $string);
    $string = str_replace("Œ", "&OElig;", $string);
    $string = str_replace("ò", "&ograve;", $string);
    $string = str_replace("ó", "&oacute;", $string);
    $string = str_replace("ô", "&ocirc;", $string);
    $string = str_replace("õ", "&otilde;", $string);
    $string = str_replace("ö", "&ouml;", $string);
    $string = str_replace("ø", "&oslash;", $string);
    $string = str_replace("œ", "&oelig;", $string);
    $string = str_replace("Ù", "&Ugrave;", $string);
    $string = str_replace("Ú", "&Uacute;", $string);
    $string = str_replace("Û", "&Ucirc;", $string);
    $string = str_replace("Ü", "&Uuml;", $string);
    $string = str_replace("ù", "&ugrave;", $string);
    $string = str_replace("ú", "&uacute;", $string);
    $string = str_replace("û", "&ucirc;", $string);
    $string = str_replace("ü", "&uuml;", $string);
    $string = str_replace("Ý", "&Yacute;", $string);
    $string = str_replace("Ÿ", "&Yuml;", $string);
    $string = str_replace("ý", "&yacute;", $string);
    $string = str_replace("ÿ", "&yuml;", $string);
    $string = str_replace("®", "&reg;", $string);
    $string = str_replace("©", "&copy;", $string);
    return $string;
} 
