﻿/* ==================================================
	MLS-Scripts Java-Scripts:	mls_jquery_calls.js
	My Last Change:				03:23 25.06.2011
	www.mylastsorrow.ch			ANBINDUNG jQUERY-PLUGINS
	Copyright by 					Stephan Schallenberger
	================================================== */


// jQuery init
jQuery(document).ready(function() {
	
    // Init Fancyboxes (single)
	jQuery('.isFancyBox').fancybox({
		'padding' 			: 10,
		'margin' 			: 40,
		'opacity' 			: false,
		'modal' 				: false,
		'cyclic' 			: false,
		'scrolling'			: 'auto',	// 'auto', 'yes' or 'no'

		'width'			 	: 800,	// 560
		'height' 			: 600,	// 340

		'autoScale' 		: false,
		'autoDimensions' 	: false,
		'centerOnScroll' 	: false,

		'hideOnOverlayClick' : true,
		'hideOnContentClick' : false,

		//	'opacity'			: false,
		//	'overlayShow'		: true,

		'speedIn' 			: 300,
		'speedOut' 			: 300,

		'changeSpeed' 		: 300,
		'changeFade' 		: 'fast',

		'easingIn' 			: 'swing',
		'easingOut' 		: 'swing',

		'titleShow' 		: true,
		'titlePosition' 	: 'inside', // 'float', 'outside', 'inside' or 'over'
		'titleFormat' 		: null,
		'titleFromAlt' 	: false,

		'transitionIn'		: 'fade',	// 'elastic', 'fade' or 'none'
		'transitionOut'	: 'fade',
			
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.7
	});


	
	/* Init Toggle-Container
		---------------------	*/
	jQuery(".toggle_container").hide();
	jQuery(".toggle_container_table").hide();
	
	// Subtitles
	jQuery("h2.toggle_trigger, h3.toggle_trigger").click(function(){
		jQuery(this).toggleClass("active").next().slideToggle("400");
		return false; //Prevent the browser jump to the link anchor
	});
	
	// Expand / Collapse ALL Toggles
	jQuery(".expand_all").toggle(function(){
		jQuery(this).addClass("expanded"); 
		}, function () {
		jQuery(this).removeClass("expanded");
	});
	jQuery(".expand_all").click(function(){
		jQuery(".toggle_container_table").slideToggle("400");
	});	
	
	
	//	Div-Containers > todo
	jQuery("div.toggle_trigger").click(function(){
		jQuery(this).toggleClass("active").next().slideToggle("fast");
	});


	
	
	/* Init Accordion-Container
		---------------------	*/
	//Set default open/close settings
	jQuery('.acc_container').hide(); //Hide/close all containers
	jQuery('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

	//On Click
	jQuery('.acc_trigger').click(function(){
		if( jQuery(this).next().is(':hidden') ) { //If immediate next container is closed...
			jQuery('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
			jQuery(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
		}
		return false; //Prevent the browser jump to the link anchor
	});



   // Init Quick-Flip
   jQuery('.quickflip-wrapper').quickFlip();




	// Init Fancyboxes (galleries)
	// *** ToDo ***
	var live = "a[rel=101204_disaster], a[rel=100505_floesser], a[rel=100227_barracuda]";
	var mixed = ", a[rel=mls_press], a[rel=gw2008], a[rel=gw2009], a[rel=gw2010], a[rel=gw2011]";
	jQuery(live + mixed).fancybox({
	//jQuery("a[rel=ex_group]").fancybox({
		'transitionIn'		: 'fade',
		'transitionOut'	: 'fade',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			// return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length  + '</span>';
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});





	/*
	*   // Init Fancyboxes (Examples - manual call)
	*/
	jQuery("#manual1").click(function() {		// 1 picture!
		jQuery.fancybox({
			//'orig'			: $(this),
			'padding'		: 0,
			'href'			: 'http://farm3.static.flickr.com/2687/4220681515_cc4f42d6b9.jpg',
			'title'   		: 'Lorem ipsum dolor sit amet',
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
    });
    
	 
	 
    // *** ToDo ***
	 jQuery("#manual3, #manual2").click(function() {	// 1 Gallery!
		
		var str = "#manual3";
		var path = "img/galleries/" + str.substr(str.length-1,1) +"/";		// letztes zeichen!
		
		jQuery.fancybox([
			path + 'mls_g1_1_b.jpg',
			path + 'mls_g1_2_b.jpg',
			path + 'mls_g1_3_b.jpg',
			path + 'mls_g1_4_b.jpg',
			{
				'href'	: path + 'mls_g1_5_b.jpg',
				'title'	: 'Titel für das letzte Bild!!!'
			}
		], {
			'padding'			: 0,
			'transitionIn'		: 'none',
			'transitionOut'	: 'none',
			'type'             : 'image',
			'changeFade'       : 0
		});
	});
	

});	// todo!



// -------------------------------------------------------------------------------------
	// Autofokus Fallback mit Abfrage, ob form-Tag auf site vorhanden ist
	var formName = jQuery("form").attr("name");
	if (formName) {
		// http://diveintohtml5.org/examples/input-autofocus-with-fallback.html
		if (!("autofocus" in document.createElement("input"))) {			// Focus
			document.getElementById("id_lastname").focus();
		}
	}


	
// -------------------------------------------------------------------------------------
// http://www.sohtanaka.com/web-design/examples/element-tooltip/

	//Tooltips
	jQuery(".tip_trigger").hover(function(){
		tip = jQuery(this).find('.tip');
		tip.show(); //Show tooltip
	}, function() {
		tip.hide(); //Hide tooltip		  
	}).mousemove(function(e) {
		var mousex = e.pageX + 20; //Get X coodrinates
		var mousey = e.pageY + 20; //Get Y coordinates
		var tipWidth = tip.width(); //Find width of tooltip
		var tipHeight = tip.height(); //Find height of tooltip
		
		//Distance of element from the right edge of viewport
		var tipVisX = $(window).width() - (mousex + tipWidth);
		//Distance of element from the bottom of viewport
		var tipVisY = $(window).height() - (mousey + tipHeight);
		  
		if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
			mousex = e.pageX - tipWidth - 20;
		} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
			mousey = e.pageY - tipHeight - 20;
		} 
		tip.css({  top: mousey, left: mousex });
	});


