// var J = jQuery.noConflict();

// wait for the DOM to be loaded

jQuery(document).ready(function() {

	////////////////////////////////////////////////////////////////////////

	// ::::::: dynamic copyright year ::::::: //

	var currentYear = (new Date).getFullYear();

	jQuery("span#copyright-year").text(currentYear);

	////////////////////////////////////////////////////////////////////////

	// ::::::: open all PDFs in a new window ::::::: //

	jQuery("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});

	////////////////////////////////////////////////////////////////////////

	// ::::::: open all external links in a new window ::::::: //

	jQuery('a[rel~=external]').attr('target', 'blank');

	////////////////////////////////////////////////////////////////////////
	
	// mark incomplete links with an image at their end

	jQuery("a[href='/images/stories/']").addClass("attention");
	
	////////////////////////////////////////////////////////////////////////
	
	// define absolute path

//	var pathname_with_hash=window.location.href;
	var site_root_url='http://'+document.location.hostname;
	var root_url_theme=site_root_url+'/wp-content/themes/Memoir/';
	var root_url_image=site_root_url+'/wp-content/themes/Memoir/images/';
	var root_url_js=site_root_url+'/wp-content/themes/Memoir/js/';
//	alert(root_url_image +'bkg_availability-no-close.png');
	var current_url=window.location.href;

//	alert( site_root_url + '#wpcf7-f2-w1-o1' );

	///////////////////////////////////////////////////////////////////////////////

//	if (current_url = site_root_url + '#wpcf7-f2-w1-o1') {
//		jQuery('#button-get-a-quote-contents').show();
//	}

	///////////////////////////////////////////////////////////////////////////////

	// availability open / close

	jQuery('div.available-msg').hide();

	jQuery('div.available-no a.a-availability').click(function() {
		if (jQuery('div.available-msg').is(':hidden') == true) {
			jQuery('div.available-msg').load(root_url_theme + '/includes/available-no.php');
//			jQuery('div.available-msg').slideDown('slow');
			jQuery('div.available-msg').show();
			jQuery('div.available-no div.button-toggle').removeClass('toggle-off');
			jQuery('div.available-no div.button-toggle').addClass('toggle-on');
		} else {
			jQuery('div.available-msg').slideUp('slow');
			jQuery('div.available-no div.button-toggle').removeClass('toggle-on');
			jQuery('div.available-no div.button-toggle').addClass('toggle-off');
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});
	
	jQuery('div.available-yes a.a-availability').click(function() {
		if (jQuery('div.available-msg').is(':hidden') == true) {
			jQuery('div.available-msg').load(root_url_theme + '/includes/available-yes.php');
//			jQuery('div.available-msg').slideDown('slow');
			jQuery('div.available-msg').show();
			jQuery('div.available-yes div.button-toggle').removeClass('toggle-off');
			jQuery('div.available-yes div.button-toggle').addClass('toggle-on');
		} else {
			jQuery('div.available-msg').slideUp('slow');
			jQuery('div.available-yes div.button-toggle').removeClass('toggle-on');
			jQuery('div.available-yes div.button-toggle').addClass('toggle-off');
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});

	///////////////////////////////////////////////////////////////////////////////
/*
	jQuery('a.presentation-button').click(function() {
		if (jQuery('div.presentation-extra').is(':hidden')) {
			jQuery('div.presentation-extra').slideDown('slow');
			jQuery('a.presentation-button').hide();	
			jQuery('a.presentation-button-close').show();
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});

	jQuery('a.presentation-button-close').click(function() {
		jQuery('div.presentation-extra').slideUp('slow');
		jQuery('a.presentation-button').show();
		jQuery('a.presentation-button-close').hide();
		return false; // prevents the browser to jump to the link anchor (#)
	});
*/

	////////////////////////////////////////////////////////////////////////

	// show & hide with div
/*
	jQuery('div.columns li a.readmore-button').click(function() {
		var theItem = jQuery(this).parent().attr('class');
		if (jQuery('div.columns li.'+theItem+' div.readmore').is(':hidden')) {
			jQuery('div.columns li.'+theItem+' div.readmore').slideDown('slow');
			jQuery('div.columns li.'+theItem+' a.readmore-button').hide();	
			jQuery('div.columns li.'+theItem+' a.readmore-button-close').show();
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});

	jQuery('div.columns li a.readmore-button-close').click(function() {
		var theItem = jQuery(this).parent().attr('class');
		jQuery('div.columns li.'+theItem+' div.readmore').slideUp('slow');
		jQuery('div.columns li.'+theItem+' a.readmore-button').show();
		jQuery('div.columns li.'+theItem+' a.readmore-button-close').hide();
		return false; // prevents the browser to jump to the link anchor (#)
	});
*/
	// show & hide with class that determines height

	jQuery('div.columns li a.readmore-button').click(function() {
		var theItem = jQuery(this).parent().attr('class');
		jQuery('div.columns li.'+theItem+' p.services').removeClass('short-intro');
		jQuery('div.columns li.'+theItem+' a.readmore-button').hide();	
		jQuery('div.columns li.'+theItem+' a.readmore-button-close').show();
		return false; // prevents the browser to jump to the link anchor (#)
	});

	jQuery('div.columns li a.readmore-button-close').click(function() {
		var theItem = jQuery(this).parent().attr('class');
		jQuery('div.columns li.'+theItem+' p.services').addClass('short-intro');
		jQuery('div.columns li.'+theItem+' a.readmore-button').show();	
		jQuery('div.columns li.'+theItem+' a.readmore-button-close').hide();
		return false; // prevents the browser to jump to the link anchor (#)
	});

	// expand & collapse all

	jQuery('a.readmore-button-all').click(function() {
		jQuery('div.columns li p.services').removeClass('short-intro');
		jQuery('div.columns li a.readmore-button').hide();	
		jQuery('div.columns li a.readmore-button-close').show();
		jQuery('a.readmore-button-all').hide();	
		jQuery('a.readmore-button-close-all').show();
		return false; // prevents the browser to jump to the link anchor (#)
	});

	jQuery('a.readmore-button-close-all').click(function() {
		jQuery('div.columns li p.services').addClass('short-intro');
		jQuery('div.columns li a.readmore-button').show();	
		jQuery('div.columns li a.readmore-button-close').hide();
		jQuery('a.readmore-button-all').show();	
		jQuery('a.readmore-button-close-all').hide();
		return false; // prevents the browser to jump to the link anchor (#)
	});

/*
	// original dynamic show & hide, which I made for joomla menu items

	jQuery('div#grandmother li a').click(function() {
		jQuery('div.shared').hide();
		var theItem = jQuery(this).parent().attr("class");
		jQuery('div#'+ theItem +'').fadeIn("fast");
		return false;
	});
	jQuery('div.shared a.close-btn').click(function() {
		jQuery(this).parent().fadeOut("fast");
		return false;
	});
*/

	///////////////////////////////////////////////////////////////////////////////

	// fix flash z-index
	jQuery('embed').attr('wmode', 'opaque');

	///////////////////////////////////////////////////////////////////////////////

	jQuery('.email').each(function(i){

		var protectedEmail = jQuery(this).html();
		protectedEmail = protectedEmail.replace("[at]","@");
		protectedEmail = protectedEmail.replace("[dot]",".");
		
		jQuery(this)
			.html(protectedEmail)
			.replaceWith("<a href=\"mailto:"+jQuery(this).text()+"?subject=[Dreamyguy.com] Contact form\">"+jQuery(this).text()+"</a>");
	});

	///////////////////////////////////////////////////////////////////////////////

	// load "get a quote" php file when one clicks on the "get a quote" button

	jQuery('a.get-a-quote').click(function() {
//		jQuery("#button-get-a-quote-contents").load(root_url_theme + '/form-get-a-quote.php');
		jQuery("#button-get-a-quote-contents").toggle();
		if (jQuery('#button-get-a-quote-contents').is(':hidden') == true) {
			jQuery('a.get-a-quote').removeClass('open');
		} else {
			jQuery('a.get-a-quote').addClass('open');
		}
		// close other contact form
		jQuery("#contact-me-contents").hide();
		if (jQuery('#contact-me-contents').is(':hidden') == true) {
			jQuery('li#menu-item-547').removeClass('current-menu-item');
		} else {
			jQuery('li#menu-item-547').addClass('current-menu-item');
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});
/*
	jQuery('a.contact-me').click(function() {
		jQuery("#button-contact-me-contents").toggle();
		if (jQuery('#button-contact-me-contents').is(':hidden') == true) {
			jQuery('a.contact-me').removeClass('open');
		} else {
			jQuery('a.contact-me').addClass('open');
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});
*/
	jQuery('li#menu-item-547 a').click(function() {
		jQuery("#contact-me-contents").toggle();
		if (jQuery('#contact-me-contents').is(':hidden') == true) {
			jQuery('li#menu-item-547').removeClass('current-menu-item');
		} else {
			jQuery('li#menu-item-547').addClass('current-menu-item');
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});

	jQuery('a.contact-me-trigger').click(function() {
		jQuery("#contact-me-contents").toggle();
		if (jQuery('#contact-me-contents').is(':hidden') == true) {
			jQuery('li#menu-item-547').removeClass('current-menu-item');
		} else {
			jQuery('li#menu-item-547').addClass('current-menu-item');
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});

	jQuery('a#close-contact').click(function() {
		jQuery("#contact-me-contents").hide();
			jQuery('li#menu-item-547').removeClass('current-menu-item');
		return false; // prevents the browser to jump to the link anchor (#)
	});

	///////////////////////////////////////////////////////////////////////////////

	// life as a webdesigner & life as a musician divs

	jQuery('a#life-as-webdesigner').click(function() {
		if (jQuery('div.life-as-webdesigner').is(':hidden') == true) {
			jQuery('a#life-as-musician').removeClass('open');
			jQuery('a#life-as-webdesigner').addClass('open');
			jQuery('div.life-as-musician').hide();
			jQuery('div.life-as-webdesigner').show();
		} else {
			jQuery('a#life-as-webdesigner').removeClass('open');
			jQuery('div.life-as-webdesigner').hide();
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});

	jQuery('a#life-as-musician').click(function() {
		if (jQuery('div.life-as-musician').is(':hidden') == true) {
			jQuery('a#life-as-webdesigner').removeClass('open');
			jQuery('a#life-as-musician').addClass('open');
			jQuery('div.life-as-webdesigner').hide();
			jQuery('div.life-as-musician').show();
		} else {
			jQuery('a#life-as-musician').removeClass('open');
			jQuery('div.life-as-musician').hide();
		}
		return false; // prevents the browser to jump to the link anchor (#)
	});

	///////////////////////////////////////////////////////////////////////////////

	// if URL contains '#wpcf7-f2-w1-o1', show form by default

	jQuery(function() {
		if(window.location.href.indexOf("#wpcf7-f2-w1-o1") != -1) {
			// alert("your url contains the name franky");
			jQuery('#button-get-a-quote-contents').show();
			jQuery('a.get-a-quote').addClass('open');
		}
	});

	///////////////////////////////////////////////////////////////////////////////

	// tooltip
	/*
	[requires '<script src="http://cdn.jquerytools.org/1.2.5/tiny/jquery.tools.min.js"></script>' on header, before this js file!]
	*/
	// select all desired input fields and attach tooltips to them
	jQuery(".wpcf7-form :input").tooltip({
		// place tooltip on the left edge
		position: "center left",
		// a little tweaking of the position
		offset: [0, -5],
		// use the built-in fadeIn/fadeOut effect
		effect: "fade",
		// custom opacity setting
		opacity: 1.0
	});

	jQuery("a#close-button").tooltip({
		// place tooltip on the left edge
		position: "center left",
		// a little tweaking of the position
		offset: [0, -5],
		// use the built-in fadeIn/fadeOut effect
		effect: "fade",
		// custom opacity setting
		opacity: 1.0
	});

	jQuery("div#social-networks a.social").tooltip({
		// place tooltip on the top edge
		position: "top center",
		// a little tweaking of the position
		offset: [-5, 0],
		// use the built-in fadeIn/fadeOut effect
		effect: "fade",
		// custom opacity setting
		opacity: 1.0,
		// CSS class name for the generated tooltip element
		tipClass: "tooltip-social"
	});

	jQuery("#login-form :input").tooltip({
		// place tooltip on the left edge
		position: "center left",
		// a little tweaking of the position
		offset: [0, -5],
		// use the built-in fadeIn/fadeOut effect
		effect: "fade",
		// custom opacity setting
		opacity: 1.0
	});

	///////////////////////////////////////////////////////////////////////////////

	// Calculate aspect ratio
/*
	// Get page document width
	var pageWidth = J(document).width();

	// Get page document height
	var pageHeight = J(document).height();

	// calculate viewport's aspect ratio
	var pageAspectratio = pageWidth / pageHeight;

	// set aspect ratio for the background image
	var imageAspectratio = 1.25;

	// set image height
	var imageHeight = 1024;

	// 1950 is minimum height: 1200 top bkg + 750 bottom bkg
	if ( pageAspectratio > imageAspectratio && pageHeight > imageHeight ) {
		J('div#main_bg').hide();
	};
*/
	// debug this...
	/*	J('div#footer-debug').html( pageAspectratio ); */
	
	///////////////////////////////////////////////////////////////////////////////	

//	jQuery('input#qname').attr('value', 'Name');

});
