// -------------------------------------------------------------------------------------------
// FANCYBOX
// -------------------------------------------------------------------------------------------
$(document).ready(function() {
	$("#reg, #login, #lostpw, #felh, a.zoomimg").fancybox({
		'titlePosition'	: 'inside',
		'padding': 1
	});
});


// -------------------------------------------------------------------------------------------
// EZMARK - CUSTOM FORM ELEMENTS
// -------------------------------------------------------------------------------------------
$(function() {
	$('.default input').ezMark();
	$('.custom input[type="checkbox"]').ezMark({checkboxCls: 'ez-checkbox-green', checkedCls: 'ez-checked-green'});

	// check all functionality
	$('#checkAllBtn').click(function(e) {
		$('input[name^="item"]').each(function() {
			$(this).attr({"checked":"checked"});
			$(this).trigger('change');
		});
		return false;
	});

	// uncheck all functionality
	$('#uncheckAllBtn').click(function(e) {
		$('input[name^="item"]').each(function() {
			$(this).removeAttr('checked');
			$(this).trigger('change');
		});
		return false;
	});
});


// -------------------------------------------------------------------------------------------
// HOVER EFFECT
// -------------------------------------------------------------------------------------------
$(window).load(function(){
	$("a.play").hover(function(){
		$("img", this).stop().animate({ "opacity": 0.3 }, 400);
		}, function() {
		$("img", this).stop().animate({ "opacity": 1 }, 250);
	});

	$("a.zoom1, a.zoom2, a.zoom3, a.zoom4, a.external").hover(function(){
		$("img", this).stop().animate({ "opacity": 0.4 }, 400);
		}, function() {
		$("img", this).stop().animate({ "opacity": 1 }, 250);
	});

	$("a.zoom3").hover(function(){
		$("img", this).stop().animate({ "opacity": 0.2 }, 400);
		}, function() {
		$("img", this).stop().animate({ "opacity": 1 }, 250);
	});
});


// -------------------------------------------------------------------------------------------
// tipTIP
// -------------------------------------------------------------------------------------------
$(function(){
	$(".tiptip").tipTip();
});


// -------------------------------------------------------------------------------------------
// CAROUSEL
// -------------------------------------------------------------------------------------------

		$(function(){
			$('#slides').slides({
				generateNextPrev: true,
				play: 2500,
				generateNextPrev: false
			});

		});


// -------------------------------------------------------------------------------------------
// CYCLE PLUGIN
// -------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------
// DROPDOWN LIST
// -------------------------------------------------------------------------------------------
$(document).ready(function() {
	$(".dropdown dt a").click(function() {
		$(".dropdown dd ul").toggle('fast');
	});

	$(".dropdown dd ul li a").click(function() {
		var text = $(this).html();
		$(".dropdown dt a span").html(text);
		$(".dropdown dd ul").hide();
	});

	function getSelectedValue(id) {
		return $("#" + id).find("dt a span.value").html();
	}

	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
			$(".dropdown dd ul").hide();
	});
});


// -------------------------------------------------------------------------------------------
// MEGA MENU
// -------------------------------------------------------------------------------------------
$(document).ready(function() {

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();

		//Calculate width of all ul's
		(function($) {
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {
					rowWidth += $(this).width();
				});
			};
		})(jQuery);

		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;
			//Calculate each row
			$(this).find(".row").each(function() {
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});

		} else { //If row does not exist...

			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});

		}
	}

	function megaHoverOut(){
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide();
	  });
	}

	var config = {
		 sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
		 interval: 50, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 500, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

	$("ul.megamenu li .sub").css({'opacity':'0'});
	$("ul.megamenu li").hoverIntent(config);
});


// -------------------------------------------------------------------------------------------
// M A I N
// -------------------------------------------------------------------------------------------


// -------------------------------------------------------------------------------------------
// IMAGE PRELOADER
// -------------------------------------------------------------------------------------------
(function($)
{
	$.fn.kriesi_image_preloader = function(options)
	{
		var defaults =
		{
			repeatedCheck: 200,
			fadeInSpeed: 500,
			delay:300,
			callback: ''
		};

		var options = $.extend(defaults, options);

		return this.each(function()
		{
			var imageContainer = jQuery(this),
				images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
				imagesToLoad = images.length;

				imageContainer.operations =
				{
					preload: function()
					{
						var stopPreloading = true;

						images.each(function(i, event)
						{
							var image = $(this);


							if(event.complete == true)
							{
								imageContainer.operations.showImage(image);
							}
							else
							{
								image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
							}

						});

						return this;
					},

					showImage: function(image)
					{
						imagesToLoad --;
						if(image.data.currentImage != undefined) { image = image.data.currentImage;}

						if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);

						if(imagesToLoad == 0)
						{
							if(options.delay > 0)
							{
								images.each(function(i, event)
								{
									var image = $(this);
									setTimeout(function()
									{
										image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
									},
									options.delay*(i+1));
								});

								if(options.callback != '')
								{
									setTimeout(options.callback, options.delay*images.length);
								}
							}
							else if(options.callback != '')
							{
								(options.callback)();
							}
						}
					}
				};
				imageContainer.operations.preload();
		});
	}
})(jQuery);


$(document).ready(function() {


    var upspd = 'slow';
    var dnspd = 'slow';

       $(function(){
        $("#nav li:has(ul)").hover(function(){

        var ul = $(this).children("ul");
        if(ul.is(":animated")){
            ul.stop()
           .css("height", "auto")
           .slideDown("dnspd");
        }
        else{
            ul.css("display", "none");
            ul.slideDown("dnspd");}},
        function(){
        var ul = $(this).children("ul");
        if(ul.is(":animated")){
          ul.stop()
            .css("height", "auto")
            .slideUp("upspd");
        }

        else{
         ul.slideUp("upspd");
        }
        });
       }); 

});


                  // initialise plugins
    jQuery(function(){
      jQuery('ul.sf-menu').superfish(
        {
            hoverClass:    'sfHover',          // the class applied to hovered list items 
            pathClass:     'overideThisToUse', // the class you have applied to list items that lead to the current page 
            pathLevels:    1,                  // the number of levels of submenus that remain open or are restored using pathClass 
            delay:         800,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
            animation:     {height:'show'},   // an object equivalent to first parameter of jQuery’s .animate() method 
            speed:         'normal',           // speed of the animation. Equivalent to second parameter of jQuery’s .animate() method 

        }
      );
    });







