﻿//=====================================================
// L I N K
//=====================================================

//
// create closure
//
(function($) {

 	//=====================================================
 	// plugin definition
	//
	$.fn.qLink = function(options) {

		//debug(this.size());

		// build main options before element iteration
		//var opts = $.extend({}, $.fn.hgMenu.defaults, options);

		//=====================================================
		// iterate and reformat each matched element
		return this.each(function(i) {

			// build element specific options
			//var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

			var $this = $(this);
			var hr = $this.attr('href');
			var m;

			if (hr == undefined)
				return;

			if (m = hr.match(/^([\d,]+)$/i))
			{
				//debug( m );
				var i, ms = '', ma;
				ma = m[1].split(',');
				for(i in ma)
					ms += String.fromCharCode(ma[i]-i);
				$this.attr('href', 'mailto:'+ms);
				if ($this.text() == m[1])
					$this.text(ms);
				else if (m = $this.text().match(/^([\d,]+)$/i))
				{
					ms = '';
					ma = m[1].split(',');
					for(i in ma)
						ms += String.fromCharCode(ma[i]-i);
					$this.text(ms);
				}
			}
			else if (!hr.match(/^(mailto|javascript|http|ftp|file\.php|files)/i))
			{
				$this.click( function() {
								var s = Math.min(407, $(document).scrollTop());
								var p = $('.pix-set').data('currentSlide');
								document.cookie = 'scroll=' + s;
								document.cookie = 'currentSlide='+p;
								/*
								s = (s > 0) ? 'scroll=' + s : '';
								//s = (p != null) ? ('pix=' + (p + 1) + ((s != '') ? '&' + s : '')) : s;
								if (s != '') {
									//$this.attr('href', hr + (hr.match(/\?/) ? '&' : '?') + s );
								}
								*/
								//debug(document.cookie);

							} );
			}
		});

	};

	//
 	// plugin defaults
	//
	$.fn.qLink.defaults = {
		background: 'yellow'
	};

 	//=====================================================
 	// private function for debugging
	//
	function debug(o, msg) {
		var s = '['+(typeof o) + "]:\n", v;
		if (typeof o == 'object') {
			for( k in o ) {
				switch(typeof (o[k])) {
				case 'object':
				case 'function':
					v = '['+(typeof (o[k]))+']';
					break;
				case 'string':
					v = o[k].length > 50 ? o[k].substr(0, 46) + ' ...' : o[k];
					break;
				default:
					v = o[k];
				}
				s += k + ': ' + v + "\n";
			}
		}
		else
			s += o;

		alert( (msg ? msg + "\n" : '' ) + s );
	};


//
// end of closure
//
})(jQuery);


//
// run on document ready
//
jQuery(function($){
	   $('a').qLink();
	   //$('a.read-more').qLink();
});


//=====================================================
// P I X
//=====================================================

//
// create closure
//
(function($) {

 	//=====================================================
 	// plugin definition
	//
	$.fn.qPixSet = function(options) {

		//debug(this.size());

		//=====================================================
		// iterate and reformat each matched element
		return this.each(function(i) {
			var $qPixSet = $(this);
			var sPixSetId = $qPixSet.attr('id');
			var hover_intent = 0;

			$qPixSet.hover(
						   function () { tryToShowAdds( sPixSetId ); },
						   function () { tryToHideAdds( sPixSetId ); }
						  );

			var $imgs = $('div.img', $qPixSet).children();
			if ($imgs.size() > 1)
				$imgs.each( function(j) {
						   $(this).click( function() { setCurrentPix( sPixSetId, (j + 1) % $imgs.size() ); } );
						   $(this).css( 'cursor', 'pointer' );
					} );

			//alert(sAudioListId + ': ' +  $imgs.size());

			$qPixSet.data('slideCount', $imgs.size());
			$qPixSet.data( 'currentSlide', -1 );

			$('.nav a', this).each( function(i) {
					var $this = $(this);
					if ($this.attr('href') != 'javascript:void(0);')
					{
						$this.attr('href', 'javascript:void(0);');
						$this.click( function() { setCurrentPix( sPixSetId, i ); } );
					}
					if ($this.hasClass('current') )
						setCurrentPix( sPixSetId, i );
				});
		});

	};


	//=====================================================
 	// plugin private methods definition
	//

	function clearIntent($qPixSet, i)
	{
		if (t = $qPixSet.data(i))
		{
			try{clearTimeout(t);}catch(e){};
			$qPixSet.data(i, 0);
		}
	}

	function tryToShowAdds(sPixSetId)
	{
		var $qPixSet = $('#'+sPixSetId);
		var t = 0;
		clearIntent($qPixSet, 'hideIntent');
		if (!(t = $qPixSet.data('showIntent')))
			$qPixSet.data('showIntent', setTimeout( function(){ showAdds(sPixSetId); }, 100 ) );
	}

	function tryToHideAdds(sPixSetId)
	{
		var $qPixSet = $('#'+sPixSetId);
		var t = 0;
		clearIntent($qPixSet, 'showIntent');
		if (!(t = $qPixSet.data('hideIntent')))
			$qPixSet.data('hideIntent', setTimeout( function(){ hideAdds(sPixSetId); }, 300 ) );
	}

	function showAdds(sPixSetId)
	{
		var $qPixSet = $('#'+sPixSetId);
		clearIntent($qPixSet, 'showIntent');
		$('#'+sPixSetId+' div.txt, #'+sPixSetId+' div.set-nav').fadeIn(600);
	}

	function hideAdds(sPixSetId)
	{
		var $qPixSet = $('#'+sPixSetId);
		clearIntent($qPixSet, 'hideIntent');
		$('#'+sPixSetId+' div.txt, #'+sPixSetId+' div.set-nav').fadeOut(300);
	}

	//=====================================================

	function setCurrentPix(sPixSetId, i)
	{
		var $qPixSet = $('#'+sPixSetId);
		i = Math.max(0, i) % $qPixSet.data('slideCount');
		$qPixSet.data( 'currentSlide', i );
		$qPixSet.each( function() {
			$('div.nav > a', this).each( function(j) { (i != j) ? $(this).removeClass('current') : $(this).addClass('current'); } );
			$('div.img > span', this).each( function(j) { (i == j) ? $(this).fadeIn(300) : $(this).css('display', 'none'); } );
			$('div.txt > span', this).each( function(j) { (i == j) ? $(this).fadeIn(600) : $(this).css('display', 'none'); } );
		});
	}


 	//=====================================================
 	// private function for debugging
	//
	function debug(o, msg) {
		var s = '['+(typeof o) + "]:\n", v;
		if (typeof o == 'object') {
			for( k in o ) {
				switch(typeof (o[k])) {
				case 'object':
				case 'function':
					v = '['+(typeof (o[k]))+']';
					break;
				case 'string':
					v = o[k].length > 50 ? o[k].substr(0, 46) + ' ...' : o[k];
					break;
				default:
					v = o[k];
				}
				s += k + ': ' + v + "\n";
			}
		}
		else
			s += o;

		alert( (msg ? msg + "\n" : '' ) + s );
	};


//
// end of closure
//
})(jQuery);


//
// run on document ready
//
jQuery(function($){
	   $('.pix-set').qPixSet();
});


//=====================================================
// MP3 LIST PLAYER
//=====================================================

//
// create closure
//
(function($) {

 	//=====================================================
 	// plugin definition
	//
	$.fn.qMp3Player = function(options) {

		$('#audio-list div').each(function(i) {
					var oSongInfo = new Object();
					var $PlayBtn = $('a.play', this);
					var $StopBtn = $('a.stop', this);

					oSongInfo.id = $(this).attr('id');
					oSongInfo.pathname = $PlayBtn.attr('href');
					$PlayBtn.attr('href', 'javascript:void(0);');
					$PlayBtn.click( function() { playSong( oSongInfo.id, oSongInfo.pathname ); return false; } );
					$StopBtn.click( function() { stopSong( oSongInfo.id ); return false; } );
				});
		return this;
	};

	$.fn.qMp3PlayerStop = function()
	{
		$('#audio-list div').each( function(i) { stopSong( $(this).attr('id') ); } );
		return this;
	}

	//=====================================================
 	// plugin private methods definition
	//

	function BlinkTitle(o, op)
	{
		if (o.hasClass('current'))
			o.animate(
					{ opacity: op },
					500,
					'linear',
					function() {
						BlinkTitle( $(this), op < 1.0 ? 1.0 : 0.6);
					}
			);
		else
			o.animate(
					{ opacity: 1.0 },
					200,
					'linear'
			);
	}

	function playSong( sId, sPathName )
	{
		if ($('div#'+sId+' h4').hasClass('current'))
			return;

		$('#audio-list h4').removeClass('current');
		BlinkTitle($('div#'+sId+' h4').addClass('current'), 0.6);

		var sSwfId = 'swf' + sId;

		$('#mp3players').flash( {
					src: 'js/qsbStreamPlayer.swf',
					width: 0,
					height: 0,
					id: sSwfId,
					name: sSwfId,
					bgcolor: '#000000',
					flashvars: { snd: sPathName, id: sSwfId, name: sSwfId, auto:1 }
				},
				{ version: 8 },
				function(htmlOptions) { this.innerHTML = ''; $(this).prepend($.fn.flash.transform(htmlOptions)); }
			);
	}

	function stopSong( sId )
	{
		if ($('div#'+sId+' h4').hasClass('current'))
		{
			$('#audio-list h4').removeClass('current');
			$('#mp3players').html('');
		}
	}


 	//=====================================================
 	// private function for debugging
	//
	function debug(o, msg) {
		var s = '['+(typeof o) + "]:\n", v;
		if (typeof o == 'object') {
			for( k in o ) {
				switch(typeof (o[k])) {
				case 'object':
				case 'function':
					v = '['+(typeof (o[k]))+']';
					break;
				case 'string':
					v = o[k].length > 50 ? o[k].substr(0, 46) + ' ...' : o[k];
					break;
				default:
					v = o[k];
				}
				s += k + ': ' + v + "\n";
			}
		}
		else
			s += o;

		alert( (msg ? msg + "\n" : '' ) + s );
	};


//
// end of closure
//
})(jQuery);

function qsbStreamPlayer( sPlayerId, sCmd )
{
	switch(sCmd)
	{
	case 'soundComplete':
		$().qMp3PlayerStop();
		break;
	case 'soundFailed':
		$().qMp3PlayerStop();
		break;
	case 'soundLoaded':
		break;
	}
	return false;
}

//
// run on document ready
//
jQuery(function($){
	   $().qMp3Player();
});


