jQuery(document).ready(function()
{
k_menu(); //improves the css dropdown menu with animation and ie6 compatibility
lavahelper(); //needed to make the lavalam menu item make work
jQuery("#nav").lavaLamp({ fx: "easeOutCubic", speed: 700 });
k_form();


/*image slider*/
slider_control('.featured_images');
interval = setInterval(function() { k_fader(".featured_item",'1'); }, 5000); // set the automatic image rotation, number is time between transitions in miliseconds

// activates the lightbox page, if you are using a dark color scheme use another theme parameter
jQuery("a[rel^='prettyPhoto'], a[rel^='lightbox']").prettyPhoto({
                                        "theme": 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */                                                                           }); 

});

function k_fader($items_to_fade, $next_or_prev)
{    
    var $items = jQuery($items_to_fade);
    var $currentitem = $items.filter(":visible");
    var $new_item;
    var $selector;
    
    if($items.length > 1)
    {
        for(i = 0; i < $items.length; i++)
        {
            if($items[i] == $currentitem[0])
            {    
                $selector = $next_or_prev >= 0 ? i != $items.length-1 ? i+1 : 0 : i == 0 ? $items.length-1 : i-1;
                
                $new_item = jQuery($items[$selector]);
                break;
            }
        }
        
        if( $new_item.css("display") == "none" )
            {    
                slider_control_update($new_item);
                $currentitem.css({zIndex:1});
                $new_item.css({zIndex:2}).fadeIn(1500, function()
                {
                    $currentitem.css({display:"none"});
                });
                
            }
    }
}



function slider_control($item_to_append)
{    
    jQuery('.featured_item a').click(function(){return false;});
    jQuery($item_to_append).each(function(){
        jQuery(this).addClass('no_hover').append("<div class='slider_control ie6fix'><a href='#' class='sc_lightbox'></a><a href='#' class='sc_external'></a><a href='#' class='sc_prev'></a><a href='#' class='sc_next'></a></div>");
        
    var $control = jQuery('.slider_control');    
    jQuery('.featured_images ').hover(
   
      function () {
        $control.fadeIn(400);
      }, 
      function () {
        $control.fadeOut(400);
      }
    );
    
    jQuery('.slider_control>a').click(function(){clearInterval(interval);});    
    
    jQuery('.slider_control>.sc_next').click(function(){
        if(jQuery('.featured_item').filter(':animated').length < 1)
        {    
            k_fader(".featured_item",'1'); 
        }
        return false;
    });
    
    jQuery('.slider_control>.sc_prev').click(function(){
        if(jQuery('.featured_item').filter(':animated').length < 1)
        {
            k_fader(".featured_item",'-1'); 
        }
        return false;
    });
        
    slider_control_update();    
    });
}

function slider_control_update($new_item)
{    
    var $item = $new_item != undefined ? jQuery($new_item) : jQuery('.featured_item').filter(":visible");
    var $external = $item.find("a").attr('href');
    var $lightbox = $item.find("a").attr('rel');

    
    if($lightbox == "" || $lightbox == undefined)
    {
        $lightbox = $item.find("img").attr('src');
    }
    
    jQuery('.slider_control>.sc_lightbox').attr({"href":$lightbox, "rel":"lightbox"});
    jQuery('.slider_control>.sc_external').attr("href", $external);

    
}



function k_menu(){
jQuery("#nav a, #subnav a").removeAttr('title');
jQuery(" #nav ul ").css({display: "none"}); // Opera Fix
jQuery(" #nav li").hover(function(){
        jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
        },function(){
        jQuery(this).find('ul:first').css({visibility: "hidden"});
        });
}



function lavahelper() 
{
    jQuery("#nav .current_page_item, #nav .current_page_parent, #nav .current_page_ancestor").addClass('current').removeClass("current_page_item").removeClass("current_page_parent").removeClass("current_page_ancestor");
}





function k_form(){
    var my_error;
    jQuery(".ajax_form #send").bind("click", function(){
                                             
    my_error = false;
    jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email ").each(function(i){
                
                
                var value = jQuery(this).attr("value");
                var check_for = jQuery(this).attr("id");
                var surrounding_element = jQuery(this).parent();
                if(check_for == "email"){
                    if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)){
                        
                        surrounding_element.attr("class","").addClass("error");
                        
                        my_error = true;
                        }else{
                        surrounding_element.attr("class","").addClass("valid");    
                        }
                    }
                
                if(check_for == "name" || check_for == "message"){
                    if(value == ""){
                        
                        surrounding_element.attr("class","").addClass("error");
                        
                        my_error = true;
                        }else{
                        surrounding_element.attr("class","").addClass("valid");    
                        }
                    }
                           if(jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email").length  == i+1){
                                if(my_error == false){
                                    jQuery(".ajax_form").slideUp(400);
                                    
                                    var $datastring = "ajax=true";
                                    jQuery(".ajax_form input, .ajax_form textarea").each(function(i)
                                    {
                                        var $name = jQuery(this).attr('name');    
                                        var $value = jQuery(this).attr('value');
                                        $datastring = $datastring + "&" + $name + "=" + $value;
                                    });
                                                                        
                                    
                                    jQuery(".ajax_form #send").fadeOut(100);    
                                    
                                    jQuery.ajax({
                                       type: "POST",
                                       url: "send.php",
                                       data: $datastring,
                                       success: function(response){
                                       jQuery(".ajax_form").before("<div class='ajaxresponse' style='display: none;'></div>");
                                       jQuery(".ajaxresponse").html(response).slideDown(400); 
                                       jQuery(".ajax_form #send").fadeIn(400);
                                       jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email , .ajax_form #website").val("");
                                           }
                                        });
                                    } 
                            }
                    });
            return false;
    });
}

/**
 * LavaLamp - A menu plugin for jQuery with cool hover effects.
 * @requires jQuery v1.1.3.1 or above
 *
 * http://gmarwaha.com/blog/?p=7
 *
 * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 0.2.0
 * Requires Jquery 1.2.1 from version 0.2.0 onwards. 
 * For jquery 1.1.x, use version 0.1.0 of lavalamp
 */

(function(jQuery) {
jQuery.fn.lavaLamp = function(o) {
    o = jQuery.extend({ fx: "linear", speed: 500, click: function(){} }, o || {});

    return this.each(function() {
        var me = jQuery(this), noop = function(){},
            jQueryback = jQuery('<li class="back"><div class="left"></div></li>').appendTo(me),
            jQueryli = jQuery("li", this), curr = jQuery("li.current", this)[0] || false;
            
            if (curr == false){jQuery(".back").remove();return false;}

        jQueryli.not(".back").not("#nav ul li").hover(function() {
            move(this);
        }, noop);

        jQuery(this).hover(noop, function() {
            move(curr);
        });

        jQueryli.click(function(e) {
            setCurr(this);
            return o.click.apply(this, [e, this]);
        });

        setCurr(curr);

        function setCurr(el) {
            jQueryback.css({ "left": el.offsetLeft+"px", "width": el.offsetWidth+"px" });
            curr = el;
        };

        function move(el) {
            jQueryback.each(function() {
                jQuery(this).dequeue(); }
            ).animate({
                width: el.offsetWidth,
                left: el.offsetLeft
            }, o.speed, o.fx);
        };

    });
};
})(jQuery);



/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function (x, t, b, c, d) {
        return c*(t/=d)*t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c *(t/=d)*(t-2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t + b;
        return -c/2 * ((--t)*(t-2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c*(t/=d)*t*t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c*((t=t/d-1)*t*t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t + b;
        return c/2*((t-=2)*t*t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c*(t/=d)*t*t*t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t=t/d-1)*t*t*t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
        return -c/2 * ((t-=2)*t*t*t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c*(t/=d)*t*t*t*t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c*((t=t/d-1)*t*t*t*t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
        return c/2*((t-=2)*t*t*t*t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t/d * (Math.PI/2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t==0) return b;
        if (t==d) return b+c;
        if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
        return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
        return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
    },
    easeInElastic: function (x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
        if (a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
        return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 0.6;
        return c*(t/=d)*t*((s+1)*t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 0.6;
        return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158; 
        if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
        return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t/=d) < (1/2.75)) {
            return c*(7.5625*t*t) + b;
        } else if (t < (2/2.75)) {
            return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
        } else if (t < (2.5/2.75)) {
            return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
        } else {
            return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
    }
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
