// JavaScript Document

jQuery.noConflict();

	 jQuery(document).ready(function($) {
			if ( document.getElementById('slider') != null )
		{
		 $('#slider').s3Slider({timeOut: 3000 });
		}


		if (jQuery.isFunction(jQuery.fn.datepicker)) {
var dates = 	$("#fromdate").datepicker({
			showOn: 'button',
			buttonImage: '/imgs/calendar-month.png',
			buttonImageOnly: true,
			dateFormat: 'dd/mm/yy'
			});
}
		if (jQuery.isFunction(jQuery.fn.datepicker)) {
var dates = $('#from, #to').datepicker({
			dateFormat: 'dd/mm/yy',
			defaultDate: "+1w",
			changeYear: true,
			changeMonth: true,
			showOn: 'button',
			buttonImage: '/imgs/calendar-month.png',
			buttonImageOnly: true,

			onSelect: function(selectedDate) {
				var option = this.id == "from" ? "minDate" : "maxDate";
				var instance = $(this).data("datepicker");
				var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
				dates.not(this).datepicker("option", option, date);
			}
			});
}



		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("dl").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: 2, // number = sensitivity threshold (must be 1 or higher)
		 interval: 100, // 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)
	};
	$("div.offer_news").find("ul:odd").css({'padding':'0 0 0 5px', 'width':'240px'});
	$("ul.toplinks li .sub").css({'opacity':'0'});
	$("ul.toplinks li").hoverIntent(config);
	$("ul.links li .sub").css({'opacity':'0'});
	$("ul.links li").hoverIntent(config);

	if ( document.getElementById('player') != null )
	{
	$("div.playlist").scrollable({
		items:'div.clips',
		vertical:true,
		next:'a.down',
		prev:'a.up'
	});
	}


	if ( document.getElementById('player') != null )
	{// setup player
	$f("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.4.swf", {
	play: {
        url: 'imgs/play.png',
        width: 44,
        height: 44
    },
		clip: {baseUrl: 'http://www.palmyra.gr/Video/'}

	// use playlist plugin to enable playlist items work as movie clips
	}).playlist("div.clips");




}
});


(function($) {
$.fn.collapsor = function(settings) {
	// override default settings
	settings = $.extend({}, $.fn.collapsor.defaults, settings);
	var triggers = this;
	// for each element
	return this.each(function() {
		// occult the collapsing elements
		$(this).find('+ ' + settings.sublevelElement).hide();
		//show the opened
		if($(this).hasClass(settings.openClass)){
			$(this).find('+ ' + settings.sublevelElement).show();
		}

		// event handling
	  $(this).click(function() {
			// remove the active class from all the elements less the clicked
			$(triggers).not($(this)).removeClass(settings.openClass);

			// if the new active have sublevels
			if ($(this).next().is(settings.sublevelElement)){
				// blur and add the active class to the clicked
				$(this).blur().toggleClass(settings.openClass);
				// toggle the clicked
				$(this).next().animate({height:'toggle', opacity:'toggle'}, settings.speed, settings.easing);
				// hide the rest
				$(this).parent().parent().find(settings.sublevelElement).not($(this).next()).animate({height:'hide', opacity:'hide'}, settings.speed, settings.easing);
				return false;
			}
	   });
	});
};


// default settings
$.fn.collapsor.defaults = {
	activeClass: 'active',
	openClass:'open',
	sublevelElement: 'dd',
	speed: 500,
	easing: 'linear'
};
})(jQuery);


