﻿jQuery.noConflict();

jQuery(document).ready(function(){
    //TOOLTIP
    //var
    var x = 10;
    var y = 30;
    var toolTip_width = 200;
    
    jQuery(".toolTip").hover(function(e){
        this.toolTip_text = this.title;
        this.title = "";
        if (this.toolTip_text) {
            var t = "<p>" + this.toolTip_text + "</p>";
        }
        else {
            var t = "";
        }
        if (this.rel) {
            jQuery("body").append("<div id='toolTip'><img src='" + this.rel + "' alt='img preview' />" + t + "</div>");
        }
        else {
        
            jQuery("body").append("<div id='toolTip'>" + t + "</div>");
        }
        jQuery("#toolTip").css("top", (e.pageY - x) + "px").css("left", (e.pageX + y) + "px").css("-moz-border-radius", "5px").fadeIn("fast");
    }, function(){
        this.title = this.toolTip_text;
        jQuery("#toolTip").remove();
    });
    jQuery(".toolTip").mousemove(function(e){
        jQuery("#toolTip").css("top", (e.pageY - x) + "px").css("left", (e.pageX + y) + "px");
    });
    
    //RASCALS "FADE" MENU
    
    /*//var
    var hoverColor = "#005b7f";
    var normalColor = "#88ddff";
    
    jQuery("ul#menu li a").before("<span></span>");
    jQuery("ul#menu li").not(".current_page_item").find("span").css("opacity", "0");
    jQuery("ul#menu li.current_page_item a").attr({
        href: "#"
    }).css({
        "cursor": "default",
        "color": hoverColor
    });
	
    jQuery("ul#menu li").not(".current_page_item").hover(function(){
        jQuery(this).find("span").stop().animate({
            opacity: 1
        }, "slow");
        jQuery(this).find("a").stop().animate({
            "color": hoverColor
        }, "slow");
    }, function(){
        jQuery(this).find("span").stop().animate({
            opacity: 0
        }, "slow");
        jQuery(this).find("a").stop().animate({
            "color": normalColor
        }, "slow");
        
    });*/
	
	//RASCALS "FADE" MENU
	
	//var
    var hoverColor = "#005b7f";
    var normalColor = "#88ddff";

	var level0 = '#menu-content div > ul > li';
	jQuery(level0).addClass('level0');
	
    jQuery(".level0 > a").before("<span></span>");
    jQuery(".level0").not(".current_page_item").find("span").css("opacity", "0");
    jQuery(".level0.current_page_item > a").attr({
        href: "#"
    }).css({
        "color": hoverColor
    });
	
    jQuery("ul#menu li").hover(function(){
		jQuery(this).find('ul:first').css('visibility', 'visible').hide().slideDown(400);
		if (jQuery(this).hasClass('level0') && !jQuery(this).hasClass("current_page_item")) {
       		jQuery(this).find("span").stop().animate({
            	opacity: 1
        	}, "slow");
        	jQuery('> a', this).stop().animate({
            	"color": hoverColor
        	}, "slow");
		}
    }, function(){
		jQuery(this).find('ul:first').css('visibility', 'hidden');
		if (jQuery(this).hasClass('level0') && !jQuery(this).hasClass("current_page_item")) {
        	jQuery(this).find("span").stop().animate({
           		opacity: 0
 	       }, "slow");
        	jQuery('> a', this).stop().animate({
            	"color": normalColor
        	}, "slow");
		}
        
    });
    
    //RSS
    jQuery("div#rss a").before("<div></div>");
    jQuery("div#rss a").prev().css("opacity", "0");
    jQuery("div#rss a").hover(function(){
        jQuery(this).prev().stop().animate({
            opacity: 1
        }, "slow");
    }, function(){
        jQuery(this).prev().stop().animate({
            opacity: 0
        }, "slow");
    });
    
    //UP
    jQuery("div#up a").before("<div></div>");
    jQuery("div#up a").prev().css("opacity", "0");
    jQuery("div#up a").hover(function(){
        jQuery(this).prev().stop().animate({
            opacity: 1
        }, "slow");
    }, function(){
        jQuery(this).prev().stop().animate({
            opacity: 0
        }, "slow");
    });
    
    jQuery("div#up a").click(function(e){
        e.preventDefault();
        var target = (window.opera) ? (document.compatMode == "CSS1Compat" ? jQuery('html') : jQuery('body')) : jQuery('html,body');
        target.animate({
            scrollTop: jQuery(jQuery(this).attr("href")).offset().top
        }, 500);
    });
    
    
    //RASCALS FORMS
    
    //var
    var message_ok = "Thank you";
    var message_error = "Can't send email!";
    var sending = "sending please wait..."
    
    var num_input = jQuery("div.rascals-form").size();
    var newsletter_path = jQuery("input#newsletter-path").val();
    var booking_path = jQuery("input#booking-path").val();
    
    //newsletter 
    var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var newsletter = jQuery(".newsletter").val();
    jQuery(".newsletter").focus(function(){
        var current_newsletter = jQuery(this).val();
        if (newsletter == current_newsletter || current_newsletter == message_ok || current_newsletter == message_error) {
            jQuery(this).val("");
        }
    }).blur(function(){
        if (jQuery(this).val() == "") {
            jQuery(this).val(newsletter);
        }
    });
    
    
    jQuery(".newsletter").keyup(function(){
        if (jQuery(this).val().match(email)) {
            jQuery(".newsletter-submit").fadeIn("slow").click(function(){
			 	var newsletter_send = jQuery(".newsletter").val();
                jQuery(".newsletter-submit").unbind("click")
                jQuery(".newsletter").val(sending);
                jQuery.post(newsletter_path, {
                    newsletter: newsletter_send
                }, function(data){
                    if (data == 'error') {
                        jQuery(".newsletter-submit").fadeOut("slow");
                        jQuery(".newsletter").val(message_error);
                    }
                    else {
                        jQuery(".newsletter-submit").fadeOut("slow");
                        jQuery(".newsletter").val(message_ok);
                    }
                });
                
            });
        }
        else {
            jQuery(".newsletter-submit").fadeOut("slow");
        }
        
    });
    
    //booking
    
    function check(){
        if (jQuery("div.rascals-form").find("span.active").size() == num_input) {
            jQuery("input#send").fadeIn("slow").click(function(){
                jQuery("input#send").unbind("click");
                jQuery(this).fadeOut("slow");
                jQuery("div.rascals-form-submit span").text(sending).fadeIn("slow");
                var form_name = jQuery("#name").val();
                var form_email = jQuery("#email").val();
                var form_message = jQuery("#message").val();
                jQuery("#name, #email, #message").val("");
                jQuery("div.rascals-form span").removeClass("active").fadeOut("slow");
                jQuery.post(booking_path, {
                    name: form_name,
                    email: form_email,
                    message: form_message
                }, function(data){
                    if (data == 'error') {
                        jQuery("div.rascals-form-submit span").text(message_error).fadeIn("slow");
                    }
                    else {
                        jQuery("div.rascals-form-submit span").text(message_ok).fadeOut(5000);
                    }
                });
                
            })
        }
        else {
            jQuery("input#send").fadeOut("slow");
        }
    }
    
    
    jQuery("#name").keyup(function(){
        if (jQuery(this).val().length > 2) {
            jQuery(this).next().addClass("active").fadeIn("slow");
            check();
        }
        else {
            jQuery(this).next().removeClass("active").fadeOut("slow");
            check();
        }
    });
    jQuery("#email").keyup(function(){
        if (jQuery(this).val().match(email)) {
            jQuery(this).next().addClass("active").fadeIn("slow")
            check();
        }
        else {
            jQuery(this).next().removeClass("active").fadeOut("slow");
            check();
        }
    });
    jQuery("#message").keyup(function(){
        if (jQuery(this).val().length > 2) {
            jQuery(this).next().addClass("active").fadeIn("slow")
            check();
        }
        else {
            jQuery(this).next().removeClass("active").fadeOut("slow");
            check();
        }
    });
    
    
    //RASCALS DYNAMIC SIDEBAR
    
    var sidebar_length = jQuery("div.dynamic-sidebar").size();
    
    for (i = 0; i < sidebar_length; i++) {
        var cookie_name = jQuery("div.dynamic-sidebar:eq(" + i + ")").attr("id");
        var cookie_value = jQuery.cookie(cookie_name);
        jQuery("div#" + cookie_value + "").find("h6").addClass("active").next("div").css("display", "block");
    }
    
    
    
    jQuery("div.dynamic-sidebar h6").click(function(){
        if (jQuery(this).is(".active")) {
        
            jQuery.cookie(jQuery(this).parent().attr("id"), null);
            jQuery(this).removeClass("active").next("div").slideUp("normal");
        }
        else {
        
            jQuery.cookie(jQuery(this).parent().attr("id"), jQuery(this).parent().attr("id"));
            jQuery(this).addClass("active").next("div").slideDown("normal");
            
        }
        
    });
    //collapse all
    jQuery("span#collapse-all").click(function(){
        if (jQuery("div.dynamic-sidebar h6").is(".active")) {
            jQuery("div.dynamic-sidebar h6").removeClass("active").next("div").slideUp("normal");
            for (i = 0; i < sidebar_length; i++) {
                var cookie_name = jQuery("div.dynamic-sidebar:eq(" + i + ")").attr("id");
                var cookie_value = jQuery.cookie(cookie_name, null);
            }
            
        }
        
    });
    jQuery("span#expand-all").click(function(){
        if (jQuery("div.dynamic-sidebar h6").not(".active")) {
            jQuery("div.dynamic-sidebar h6").addClass("active").next("div").slideDown("normal");
            for (i = 0; i < sidebar_length; i++) {
                var cookie_name = jQuery("div.dynamic-sidebar:eq(" + i + ")").attr("id");
                var cookie_value = jQuery.cookie(cookie_name, cookie_name);
            }
        }
        
    });
    
})
;(function($) {
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // NOTE Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

})(jQuery);

/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery);
