
//-----------------------------
// $(document).ready() 
//-----------------------------
$(document).ready(function() {
    $('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: 200, // the delay in milliseconds that the mouse can remain outside a submenu without it closing
      // animation: {opacity:'show'}, // an object equivalent to first parameter of jQuery?s .animate() method
      speed: 300, // speed of the animation. Equivalent to second parameter of jQuery?s .animate() method
      // autoArrows: true, // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance
       dropShadows: false // completely disable drop shadows by setting this to false
      // disableHI: false, // set to true to disable hoverIntent detection
       //onInit: function(){}, // callback function fires once Superfish is initialised ? 'this' is the containing ul 
       //onBeforeShow: function(){}, // callback function fires just before reveal animation begins ? 'this' is the ul about to open 
      // onShow: function(){}, // callback function fires once reveal animation completed ? 'this' is the opened ul 
      // onHide: function(){} // callback function fires after a sub-menu has closed ? 'this' is the ul that just closed
    });
	$("a[tooltipid]").tooltip({
		delay: 100,
		track: true,
		showBody: "|",
		extraClass: "tooltip_Cal",
		top: 15,
		left: 15,
		bodyHandler: function() {
			if ($(this).attr("tooltipTitle")!=undefined) {
				$('#tooltip h3').html($(this).attr("tooltipTitle")).show();
			} else {
				$('#tooltip h3').hide();
			}
			return $('#'+$(this).attr("tooltipid")).html();
		},
		showURL: false
	});
	$('.date').datepicker({changeYear:true,changeMonth:true,yearRange:'1912:2012'});
	$('.over18').datepicker({changeYear:true,changeMonth:true,yearRange:'1912:2012',maxDate:'-18y'});
	$('.over13').datepicker({changeYear:true,changeMonth:true,yearRange:'1912:2012',maxDate:'-13y'});
	$('.over5').datepicker({changeYear:true,changeMonth:true,yearRange:'1912:2012',maxDate:'-5y'});
	$('.futuredate').datepicker({changeYear:true,changeMonth:true,yearRange:'2012:2022',minDate:'-0d'});
	$('.pastdate').datepicker({changeYear:true,changeMonth:true,yearRange:'1994:2012',maxDate:'-0d'});
	$('input[placeholder]').placeholder({blankSubmit:true});
	$.smoothAnchors(1500, "easeInOutQuad", false);
	$('#flip').jcoverflip({
		current: 0,
		time: 350,
		beforeCss: function( el, container, offset ){
			return [
				$.jcoverflip.animationElement( el, { left: ((container.width()/2 - 205) - (105*offset))+'px', bottom: '50px', borderWidth: '0px' }, {} ),
				$.jcoverflip.animationElement( el.find( 'img' ), { width: '100px' }, {} )
			];
		},
		afterCss: function( el, container, offset ){
			return [
				$.jcoverflip.animationElement( el, { left: ((container.width()/2 + 107) + (107*offset))+'px', bottom: '50px', borderWidth: '0px' }, {} ),
				$.jcoverflip.animationElement( el.find( 'img' ), { width: '100px' }, {} )
			];
		},
		currentCss: function( el, container ){
			return [
				$.jcoverflip.animationElement( el, { left: ( container.width()/2 - 100 )+'px', bottom: 0, borderWidth: '1px' }, {} ),
				$.jcoverflip.animationElement( el.find( 'img' ), { width: '200px' }, { } )
			];
		},
		change: function(event, ui){
			$('#scrollbar').slider('value', ui.to);
		  }
	});
	$(".UIBtn").css('font-size', '10px').button();
	
	$('a.ajaxdialog').click(function() { 
		var url = this.href;
		var ttl = this.title?this.title:'';
		$.ajax({
			  url: url,
			  cache: false,
			  async: true,
			  success: function(html){ 
				$('#UIModalContent').dialog('destroy').html(html).dialog({
					title: ttl, modal: true, width: 450, height:300, resizable: false,
					buttons:{"Close": function() { $(this).dialog("close"); }},
					open: function(event, ui) {
						//$(this).dialog( "option", "position", 'center' );
						$(this).parent().css("left",($(window).width()-$(this).width())/2+"px");
						$(this).parent().css("top",($(window).height()-$(this).height())/2+"px");
						$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
					},
					dragStop: function(event, ui){
						$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
					}
				});
			}
		});
		return false; 
	});
	$('a.dialog').click(function() { 
		var html = $(this).attr('content') ? $(this).attr('content') : $('#'+this.name).html();
		var ttl = this.title ? this.title : '';
		$('#UIModalContent').dialog('destroy').html(html).dialog({
			title: ttl, modal: true, width: 450, height:300, resizable: false,
			buttons:{"Close": function() { $(this).dialog("close"); }},
			open: function(event, ui) {
				$(this).parent().css("left",($(window).width()-$(this).width())/2+"px");
				$(this).parent().css("top",($(window).height()-$(this).height())/2+"px");
				$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
			},
			dragStop: function(event, ui){
				$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
			}
		});
		return false;
	});
	$('a.dialogframe').click(function() { 
		var url = this.href;
		var ttl = this.title ? this.title : '';
		$('#UIModalContent').dialog('destroy').html('<iframe src="'+url+'" name="dialog_frame" width="100%" marginwidth="0" height="100%" marginheight="0" scrolling="auto" frameborder="0" hspace="0" vspace="0" allowtransparency="true"></iframe>').dialog({
			title: ttl, modal: true, width: 785, height:550, resizable: false,
			buttons:{"Close": function() { $(this).dialog("close"); }},
			open: function(event, ui) {
				$(this).parent().css("left",($(window).width()-$(this).width())/2+"px");
				$(this).parent().css("top",($(window).height()-$(this).height())/2+"px");
				$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
			},
			dragStop: function(event, ui){
				$(this).attr("uimtop",$(this).parent().offset().top-$(window).scrollTop()).attr("uimleft",$(this).parent().offset().left);
			}
		});
		return false;
	});
    $('a.email').nospam({replaceText:true});
    
	applyFancyBox();
	
	$('a[scAlbumLink]').click( function() {
		showScrollableAlbum( $(this).attr("scAlbumLink") );
	});
	
	if ($('.vfloat').exists()) {
    	var top = $('.vfloat').offset().top - parseFloat($('.vfloat').css('marginTop').replace(/auto/, 0));
    } else {
    	var top = 0;
    }
    
	var top2 = $('#UIModalContent').parent().offset().top - parseFloat($('#UIModalContent').parent().css('marginTop').replace(/auto/, 0));
	$(window).scroll(function (event) {
		fixSidebar();
	});

	function fixSidebar(){
		var y = $(this).scrollTop();
		if (y >= top) {
			$('.vfloat').addClass('fixed');
			$('.vfloat_hide').hide();
		} else {
			$('.vfloat').removeClass('fixed');
			$('.vfloat_hide').show();
		}
		$('#UIModalContent').parent().css("top",(parseInt($('#UIModalContent').attr("uimtop"))+parseInt(y))+"px");
		$('.ui-widget-overlay').height($(window).height());
		$('.ui-widget-overlay').css('top',y);
	}
	
	
	$(".scrollable").scrollable({
			
			speed: 1300,
			circular: true, 
			mousewheel: true
		}).navigator();
    
	initISSjs();
});

