/**
 * @author Marcin
 */

/*-----------------------------------------------------------------------
Functions
------------------------------------------------------------------------*/
jQuery.fn.nospam = function(settings) {
	settings = jQuery.extend({
		replaceText: false, 	// optional, accepts true or false
		filterLevel: 'normal' 	// optional, accepts 'low' or 'normal'
	}, settings);
	return this.each(function(){
		e = null;
		if(settings.filterLevel == 'low') { // Can be a switch() if more levels added
			if(jQuery(this).is('a[rel]')) {
				e = jQuery(this).attr('rel').replace('/', '@').replace('/', '.');
			} else {
				e = jQuery(this).text().replace('/', '@').replace('/', '.');
			}
		} else { // 'normal'
			if(jQuery(this).is('a[rel]')) {
				e = jQuery(this).attr('rel').split('').reverse().join('').replace('/', '@').replace('/', '.');
			} else {
				e = jQuery(this).text().split('').reverse().join('').replace('/', '@').replace('/', '.');
			}
		}
		if(e) {
			if(jQuery(this).is('a[rel]')) {
				jQuery(this).attr('href', 'mailto:' + e);
				if(settings.replaceText) {
					jQuery(this).text(e);
				}
			} else {
				jQuery(this).text(e);
			}
		}
	});
};

$.fn.slowfade = function(default_options) 
{
	var defaults = 
	{  
		duration:400,
		opacity:1,
		add_inner_html:false, 	//set true for text links
		use_class:false, 		// set to classname
		use_span_class:false, 	// set to classname
		ie6comp:false 			//ie6 compatibility mode, used when ie6 is used and wrapping item has no fixed width, set to classname
	};  
	var default_options = $.extend(defaults, default_options); 
	
	return this.each(function()
	{	
		var my = $(this);
		var $pos = my.css("position") == "absolute" ? "absolute" : "relative";
		var $bg = my.css("background-position") === undefined ? my.css("background-position-x") + ' ' + my.css("background-position-y") : my.css("background-position");
		var $inner_html = default_options.add_inner_html ? my.text() : "";
		
		if(!default_options.use_class)
		{
			my.css({position:$pos, backgroundPosition:"right bottom"});
		}
		else
		{
			my.addClass(default_options.use_class);
		}
		
		if(!default_options.use_span_class)
		{
			$hover_replace = $('<span>'+$inner_html+'</span>').appendTo(my).css(
			{	
				height: my.height(), width: my.width(), backgroundImage: my.css("background-image"), backgroundPosition: $bg,
				cursor: "pointer", position:"absolute",top:"0",left:"0",display:"block"
			});
		}
		else
		{
			$hover_replace = $('<span class="'+default_options.use_span_class+'">'+$inner_html+'</span>').appendTo(my);
		}
		
		if(default_options.ie6comp && $.browser.msie && $.browser.version.substr(0,1)<7)
		{
			$hover_replace.css({height: my.height(), width: my.width()}).addClass(default_options.ie6comp);
		}
					
		
		$hover_replace.hover(
		function()
		{	
			$(this).stop().animate({opacity: 0},default_options.duration);	
			if(default_options.opacity != 1) my.stop().animate({opacity: default_options.opacity},default_options.duration);	
		},
		function()
		{
			$(this).stop().animate({opacity: 1},default_options.duration);
			if(default_options.opacity != 1) my.stop().animate({opacity: 1},default_options.duration);	

		});
	});	
}


/*-----------------------------------------------------------------------
On Load
------------------------------------------------------------------------*/
$(function() {
	$("a[rel^='prettyPhoto']").prettyPhoto({
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		theme: 'marengo_rounded' /* light_rounded / dark_rounded / light_square / dark_square */	
	});


	$("a.homeballroom, a.homefreestyle").slowfade({use_span_class:"slowfade",use_class:"slowfade_mod", add_inner_html:true, ie6comp:"ie6fix"});
	$('a.towdescr, a.bloggallerysingle, a.nowdescr').hover(
      function () {
        $(this).css('opacity', '0.6');
      }, 
      function () {
        $(this).css('opacity', '1.0');
    });
	$('a.spamemail').nospam();
	
	var site_url = jQuery("meta[name=helper]").attr('content');
	$('#gallerytow').flash(
        { src: site_url+'/swf/orange.swf',
          width: 690,
          height: 510,
		  flashvars: { xmlfile: site_url+'/uploads/gallerytow.xml' },
		  wmode: 'transparent'},
        { version: 9 }
    );
	$('#gallerynow').flash(
        { src: site_url+'/swf/blue.swf',
          width: 690,
          height: 510,
		  flashvars: { xmlfile: site_url+'/uploads/gallerynow.xml' },
		  wmode: 'transparent'},
        { version: 9 }
    );
});




