/*
 * JS scripts for CEF v4 
 */
 
// fix for IE ClearType bug - http://blogs.msdn.com/ie/archive/2006/02/03/524367.aspx
// related posts: http://drupal.org/files/issues/jquerymenu-cleartype.patch
// requires to pass sped and callback parameters
(function($) {
	$.fn.fixClearTypeBug = function(speed, callback) {
		$(this).fadeIn(speed, function() {  // or may add nice effect to restore like fadeIn or fadeOut
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

// drop down menu
// http://picssel.com 2010
 $(function(){
	$('#menu li ul').hide(); //fix flickering in opera
	$('#menu li').hover(function() {
		$(this).children('a').addClass('bebe');
		$(this).children('ul').hide().stop(true, true).delay(100).slideDown(300);}
		, 
		function() {
		$(this).children('a').removeClass('bebe');
		$(this).children('ul').stop(true, true).delay(200).slideUp(200); 
	});

});
// image replacement
// http://www.jeffsarmiento.com/2008/06/05/jquery-image-replacement/
// picssel.com 24 Aug 2011 - works as function before DOM
$(function(){
$(".imgreplace").each(function() {
string = $(this).text();
filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
$(this).html('<img src="images4/' + filename + '.gif" alt="' + string + '" />');
});
}); // image replacement

// document ready
	$(document).ready(function() {

//fancybox custom scripts ///////////////////////////////

	$("a.fancyimage").fancybox({
	'padding': 0,
	'overlayOpacity': 0.8,
	'overlayColor': '#333'
	});
	$("a.fancycard").fancybox({
	'overlayOpacity': 0.8,
	'overlayColor': '#333',
	'titleShow': false,
	'autoScale': false
	});
	$("a.fancyshoot").fancybox({
		'padding': 0,
		'width': 640,
		'height': 480,
		'autoScale': false,
		'overlayOpacity': 0.8,
		'overlayColor': '#333',
		'scrolling': 'no',
		'type':'iframe'
		});
	$(".fancypdf").click(function() {
	$.fancybox({
		'width': '75%',
		'height': '90%',
		'autoDimensions': false,
		'overlayOpacity': 0.8,
		'overlayColor': '#333',
		'content': '<embed src="'+this.href+'#nameddest=self&page=1&view=FitH,0&zoom=80,0,0" type="application/pdf" height="99%" width="100%" />',
		'onClosed': function() {
				$("#fancybox-inner").empty();
			}
		});
		return false;
	}); // pdf	
$("a.fancymodal").fancybox({
	'padding': 0,
	'modal': true,
	'width': '90%', 
	'height': '85%', 
	'overlayShow': true,
	'overlayOpacity': 0.8,
	'overlayColor': '#333',
	'type': 'iframe',
	'titlePosition': 'over',	
	'titleFormat': function() {
		return '<span id="fancybox-title-over"><a style="top: 0; color:#fff; text-decoration: none; line-height: 30px;" href="javascript:;" onclick="parent.$.fancybox.close();"><strong>CLOSE&nbsp;&nbsp;</strong><img style="vertical-align:middle;" src="/images4/fancy_close.png" alt="close" /></a>&nbsp;&nbsp;&nbsp;</span>';
	},
	'onComplete': function() {
		$("#fancybox-title").css({'top':'-40px', 'bottom':'auto', 'text-align':'right'});
	}
});// fancymodal
$("a.fancymap").fancybox({
	'padding': 0,
	'width': 640,
	'height': 360,
	'overlayOpacity': 0.8,
	'overlayColor': '#333',
	'type': 'iframe'
}); //fancymap

$("a.fancyvideo").fancybox({
	'padding': 0,
	'width': 500,
	'height': 399,
	'overlayOpacity': 0.8,
	'overlayColor': '#333',
	'autoScale': false,
	'type': 'swf',
	'swf': {'wmode':'transparent', 'allowfullscreen': true}
	}); //fancyvideo

$(".fancy5years").fancybox({
	'padding': 0, 
	'width': 864,  /*864*/ 
	'height': 510, /*486*/ 
	'autoScale': false, 
	'overlayOpacity': 0.8, 
	'overlayColor': '#333', 
	'type': 'swf', 
	'swf': {'wmode':'transparent', 'allowfullscreen': true}
	}); //fancy5years
// end fancybox

// section selector
// http://picssel.com 2010
// initialize sections for projects section - show first as active
	$("div.section").hide().eq(0).fixClearTypeBug(0); 
	$("ul.thirdNav a").eq(0).addClass("current");
// bind options to sections
	$("ul.thirdNav a").each(function(i) {
		$(this).bind("click",function(){
			$("ul.thirdNav a").removeClass("current").eq(i).addClass("current");
			$("div.section").hide().eq(i).fixClearTypeBug(0); 
	//		$(window).scrollTop(156);
	//		$(window).scrollTop(430); //
		}); //bind select
	});//each
//

// ajusta fonts en IE
// $("ul#menu li ul li a").

// select photo shoot location
// http://picssel.com 2011
// initialize location for photoshoots section - show first as active
	var subMenu3  = jQuery('.thirdNav');
	var selectorLocation = jQuery('.location');
	subMenu3.hide().eq(0).show();
	selectorLocation.eq(0).addClass('opened').css({'fontWeight':'bold','cursor':'normal','color':'#040404'});
	selectorLocation.hover(
		function () {
			if(!jQuery(this).hasClass("opened")) {jQuery(this).css({'fontWeight':'bold','cursor':'pointer','color':'#D88E21'}); }
		}, function () {
			if(!jQuery(this).hasClass("opened")) {jQuery(this).css({'fontWeight':'normal','cursor':'normal','color':'#040404'}); }
		}
	); // hover
	selectorLocation.each(function(i) {
		jQuery(this).bind("click",function(){
			if(!selectorLocation.eq(i).hasClass("opened")) {
				selectorLocation.removeClass('opened')
				.css({'fontWeight':'normal','cursor':'normal','color':'#040404'})
				.eq(i).addClass('opened').css({'fontWeight':'bold','cursor':'normal','color':'#040404'});
				subMenu3.slideUp(200).eq(i).slideDown(300);
				subMenu3.eq(i).find('li:first a').trigger('click');
			}	// if
		}); // bind location
	});// each	

}); //ready
