/**
 * @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);
			}
		}
	});
};

function do_actions(){
	jQuery("#concertspage .toggle_container").hide();
	jQuery("#concertspage .trigger").css('cursor', 'pointer');
	jQuery("#concertspage .trigger").append(" (kliknij aby zobaczyć...)");
	jQuery("#concertspage .trigger").click(function(){
		jQuery(this).next(".toggle_container").slideToggle("slow");
	}); 
	Cufon.replace('.contentcol .post h2 a, .contentcol .post h2, #information h3, #information span, h4, h5');
	jQuery('a.spamemail').nospam();
	jQuery('#gallery a, .gallerypost a').hover(
      function () {
        jQuery(this).css('opacity', '0.5');
      }, 
      function () {
        jQuery(this).css('opacity', '1.0');
    });
	jQuery('#discography .album').hover(function(){
		jQuery(this).find('.album-desc').fadeIn(250);
		}, function(){
		jQuery(this).find('.album-desc').fadeOut(250);
	});
	/* TURN ON PRETTYPHOTO */
	jQuery(document).ready(function(){
		jQuery("a[rel^='prettyPhoto']").prettyPhoto({
			showTitle: false, /* true/false */
			allowresize: true, /* true/false */
			theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square */	
		});
	});
	do_othernav_ajax();
}

	
/* REWRITE MAINNAV LINKS, DO AJAX LOAD */
function do_mainnav_ajax(){
	jQuery(".page_item a:not(.page-item-7 a), .menu-item a:not(.menu-item-7 a), #postnav a, a[rel^='innerlink']").click(function(){
		jQuery('.content').loading("show", {
			align: 'top-center', 
			text: 'Wczytuje...',
			mask: true, 
			maskCss: { 
				position:'absolute',
				opacity:.5,
				background:'#000',
                zIndex:101,
				display:'block',
				cursor:'wait' 
			}
		});		
		var href	= jQuery(this).attr('href');
		var target 	= href + ' .content';
		jQuery("#tempcont").css('display', 'none')
		jQuery("#tempcont").load(target, function() {			
	  		var contents = jQuery("#tempcont").contents();	
			var newHeight = jQuery("#tempcont").height();
			jQuery("#center-inner .content").animate({height: newHeight, opacity: 0}, 1000, function(){
				jQuery("#center-inner .content").replaceWith(contents);
				jQuery("#center-inner .content").css('display', 'none');
					do_actions();
				jQuery("#center-inner .content").fadeIn(1000, function(){
					
				});
			});
		});
		return false;
	});	
}

/* REWRITE DISCOGRAPHY LINKS, DO AJAX LOAD */
function do_othernav_ajax(){
	jQuery("#discography a, #postnav a, p.comments a, a[rel^='innerlink']").click(function(){
		jQuery('.content').loading("show", {
			align: 'top-center', 
			text: 'Wczytuje...',
			mask: true, 
			maskCss: { 
				position:'absolute',
				opacity:.5,
				background:'#000',
                zIndex:101,
				display:'block',
				cursor:'wait' 
			}
		});		
		var href	= jQuery(this).attr('href');
		var target 	= href + ' .content';
		jQuery("#tempcont").css('display', 'none')
		jQuery("#tempcont").load(target, function() {			
	  		var contents = jQuery("#tempcont").contents();	
			var newHeight = jQuery("#tempcont").height();
			jQuery("#center-inner .content").animate({height: newHeight, opacity: 0}, 1000, function(){
				jQuery("#center-inner .content").replaceWith(contents);
				jQuery("#center-inner .content").css('display', 'none');
					do_actions();
				jQuery("#center-inner .content").fadeIn(1000, function(){
					
				});
			});
		});
		return false;
	});	
}

/*ON LOAD*/
jQuery(function() {
	/* DO ACTIONS IF AJAX NOT WORKING */
	do_actions();	
	do_mainnav_ajax();
	do_othernav_ajax();
	

	/* ADD FLASH */
	var site_url = jQuery("meta[name=helper]").attr('content');
	var site_xml = jQuery("meta[name=helper]").attr('content') + '/xmlplaylist/?date=20100105';
	
	/*jQuery('#flash').flash(
        { src: site_url+'/swf/flash.swf',
          width: 960,
          height: 475,
		  wmode: 'transparent'},
        { version: 10 }
    );*/
	
	/* The player stuff */
	jQuery('#player #playertoggler').click(function(){
		if ( jQuery('#player #playercontent').hasClass("active") ) {
			jQuery('#player #playercontent').css('right', '9999px');
			jQuery('#player #playertoggler a').css('background-position', '-22px 0');
			jQuery('#player #playercontent').removeClass("active");
			
		} else {
			jQuery('#player #playercontent').css('right', '22px');
			jQuery('#player #playertoggler a').css('background-position', '0 0');
			jQuery('#player #playercontent').addClass("active");
		}

	});
	
	jQuery('#player #playertoggler').hover(
      function () {
        jQuery(this).css('background-position', '-22px 0');
      }, 
      function () {
        jQuery(this).css('background-position', '0 0');
      })

	

	jQuery('#player #playercontent').flash(
        { 
			src: site_url+'/swf/player.swf',
			width: 400,
			height: 418,
			allowfullscreen: 'false',
			allowscriptaccess: 'always',
			wmode: 'opaque',
			flashvars: { 
				file: site_xml,
				skin: site_url + '/swf/stylish_slim.swf',
				playlist: 'bottom',
				autostart: true
			}
        },
        { version: 9 }
    );

	
	
});




