﻿$(document).ready(function(){
//---------------------------------------------					   						   						   
	$('#slideshow').cycle({ 
     	fx: 'fade', 
		width: '400px',
		height: '260px',
		speed: 2500,
		timeout: 8000,
    	random:  1 
	});
  	//---------------------------------------------					   						   
	$("#scroller").simplyScroll({
			autoMode: 'loop'
	});
	//---------------------------------------------					   						   
	$("#home").click(function () {
    	$(this).effect("bounce", { times:3 }, 300);
	});						   
	//---------------------------------------------					   
	$("#horizontal_menu li a").click(function () {
    	$(this).effect("bounce", { times:5 }, 300);
		//$(this).show("explode", 1000);
	});
	//---------------------------------------------					   	
});


//--------------------------------------- ScrollBy -----------------------------------------

function goToByScroll(id, offset){
	      $('html,body').animate({scrollTop: $("#"+id).offset().top + offset},'slow');//slow & fast
}
//----------------------------------- Load HTML to DIV  ------------------------------------
function LoadHTML(URL){ 
	CenterDiv('Loading');
	document.getElementById('Loading').style.visibility='visible';
	
	//$(document).ready(function() { //LOAD IFRAME
	    //$('#post_area_iframe').show("slide", { direction: "up" }, 600);
		//$('#post_area_iframe').show("fade", {}, 1000);
		//$('#post_area_iframe').load(URL);
	 	//$('#post_area_iframe').attr('src', URL );
		
		//window.setTimeout("document.getElementById('Loading').style.visibility='hidden';",1000);
	 //});    		
	
	document.getElementById('post_area_iframe').style.visibility='hidden';

	 if (!document.all){
			myiframe = document.getElementById('post_area_iframe');
			myiframe.src = URL;
		}
	else if (document.all){
			myiframe = document.all['post_area_iframe'];
			myiframe.src = URL;
	}

}
//--------------------------------------------------------------------------------------------
function hideLoading(){
	top.document.getElementById('Loading').style.visibility='hidden';
}
//--------------------------------------------------------------------------------------------
function calcHeight(){ 
	document.getElementById('post_area_iframe').height = 0;
	if (!document.all) {
		var the_height = document.getElementById('post_area_iframe').contentDocument.documentElement.scrollHeight+30; //FF, Opera
	}else{
		var the_height = document.getElementById('post_area_iframe').contentWindow.document.body.scrollHeight+30; //IE CROME
	}
	document.getElementById('post_area_iframe').height = the_height;

	document.getElementById('post_area_iframe').style.visibility='visible';
}


function CenterDiv(id){
		var scrOfX = 0, scrOfY = 0;
  		if( typeof( window.pageYOffset ) == 'number' ) {
    			//Netscape compliant
    			scrOfY = window.pageYOffset;
    			scrOfX = window.pageXOffset;
  		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    			//DOM compliant
   		 	scrOfY = document.body.scrollTop;
	 		scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		    	//IE6 standards compliant mode
		    	scrOfY = document.documentElement.scrollTop;
		    	scrOfX = document.documentElement.scrollLeft;
		}



		if (!document.all){
			myCenterDIV = document.getElementById(id);
			myheight = document.getElementById(id).clientHeight; 
			mywidth  = document.getElementById(id).clientWidth; 
			document.getElementById(id).style.top  = ( (window.innerHeight / 2 ) - ( myheight / 2 ) ) + scrOfY + "px";
			document.getElementById(id).style.left = ( (window.innerWidth  / 2 ) - ( mywidth  / 2 ) ) + scrOfX + "px";
		}
		else if (document.all){
			myCenterDIV = document.all[id];
			myheight = document.all[id].clientHeight; 
			mywidth  = document.all[id].clientWidth; 
			document.all[id].style.top  = ( (document.documentElement.clientHeight / 2) - ( myheight / 2 ) ) + scrOfY + "px";
			document.all[id].style.left = ( (document.documentElement.clientWidth  / 2) - ( mywidth  / 2 ) ) + scrOfX + "px";
		}
}
//-------------------------------------- Tooltip ------------------------------------------
 $(document).ready(function() {
   $(".someClass").tipTip({maxWidth: "200px", edgeOffset: 2, defaultPosition:"bottom" });
 });

//------------------------------------ Reflection  ----------------------------------------

//$(document).ready(function() {
//	        $('#div_block').reflect({height:0.5,opacity:0.9});
	        //$('img').reflect({height:0.5,opacity:0.9});
//}); 

//------------------------------------------- Time -----------------------------------------
function ShowTime() {
  var dt = new Date();
  document.getElementById("tools_time").innerHTML = dt.toLocaleTimeString();
  window.setTimeout("ShowTime()", 1000);
}  

//------------------------------------------- Date -----------------------------------------
function ShowDate() {
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	document.write(year + "." + month + "." + day)
	//document.getElementById("tools_time").innerHTML = year + "." + month + "." + day;
}

//--------------------------------------- Mediaplyer --------------------------------------
$(document).ready(function(){

	var Playlist = function(instance, playlist, options) {
		var self = this;

		this.instance = instance; // String: To associate specific HTML with this playlist
		this.playlist = playlist; // Array of Objects: The playlist
		this.options = options; // Object: The jPlayer constructor options for this playlist

		this.current = 0;

		this.cssId = {
			jPlayer: "jquery_jplayer_",
			interface: "jp_interface_",
			playlist: "jp_playlist_"
		};
		this.cssSelector = {};

		$.each(this.cssId, function(entity, id) {
			self.cssSelector[entity] = "#" + id + self.instance;
		});

		if(!this.options.cssSelectorAncestor) {
			this.options.cssSelectorAncestor = this.cssSelector.interface;
		}

		$(this.cssSelector.jPlayer).jPlayer(this.options);

		$(this.cssSelector.interface + " .jp-previous").click(function() {
			self.playlistPrev();
			$(this).blur();
			return false;
		});

		$(this.cssSelector.interface + " .jp-next").click(function() {
			self.playlistNext();
			$(this).blur();
			return false;
		});
	};

	Playlist.prototype = {
		displayPlaylist: function() {
			var self = this;
			$(this.cssSelector.playlist + " ul").empty();
			for (i=0; i < this.playlist.length; i++) {
				var listItem = (i === this.playlist.length-1) ? "<li class='jp-playlist-last'>" : "<li>";
				listItem += "<a href='#' id='" + this.cssId.playlist + this.instance + "_item_" + i +"' tabindex='1'>"+ this.playlist[i].name +"</a>";

				// Create links to free media
				if(this.playlist[i].free) {
					var first = true;
					listItem += "<div class='jp-free-media'>(";
					$.each(this.playlist[i], function(property,value) {
						if($.jPlayer.prototype.format[property]) { // Check property is a media format.
							if(first) {
								first = false;
							} else {
								listItem += " | ";
							}
							listItem += "<a id='" + self.cssId.playlist + self.instance + "_item_" + i + "_" + property + "' href='" + value + "' tabindex='1'>" + property + "</a>";
						}
					});
					listItem += ")</span>";
				}

				listItem += "</li>";

				// Associate playlist items with their media
				$(this.cssSelector.playlist + " ul").append(listItem);
				$(this.cssSelector.playlist + "_item_" + i).data("index", i).click(function() {
					var index = $(this).data("index");
					if(self.current !== index) {
						self.playlistChange(index);
					} else {
						$(self.cssSelector.jPlayer).jPlayer("play");
					}
					$(this).blur();
					return false;
				});

				// Disable free media links to force access via right click
				if(this.playlist[i].free) {
					$.each(this.playlist[i], function(property,value) {
						if($.jPlayer.prototype.format[property]) { // Check property is a media format.
							$(self.cssSelector.playlist + "_item_" + i + "_" + property).data("index", i).click(function() {
								var index = $(this).data("index");
								$(self.cssSelector.playlist + "_item_" + index).click();
								$(this).blur();
								return false;
							});
						}
					});
				}
			}
		},
		playlistInit: function(autoplay) {
			if(autoplay) {
				this.playlistChange(this.current);
			} else {
				this.playlistConfig(this.current);
			}
		},
		playlistConfig: function(index) {
			$(this.cssSelector.playlist + "_item_" + this.current).removeClass("jp-playlist-current").parent().removeClass("jp-playlist-current");
			$(this.cssSelector.playlist + "_item_" + index).addClass("jp-playlist-current").parent().addClass("jp-playlist-current");
			this.current = index;
			$(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
		},
		playlistChange: function(index) {
			this.playlistConfig(index);
			$(this.cssSelector.jPlayer).jPlayer("play");
		},
		playlistNext: function() {
			var index = (this.current + 1 < this.playlist.length) ? this.current + 1 : 0;
			this.playlistChange(index);
		},
		playlistPrev: function() {
			var index = (this.current - 1 >= 0) ? this.current - 1 : this.playlist.length - 1;
			this.playlistChange(index);
		}
	};

	
	var audioPlaylist = new Playlist("2", [
		{
			name:"1. Distant sound of the sea",
			mp3:"js/mediaplayer/sound/DistantSoundOfTheSea.mp3",
		},
		{
			name:"2. Beyond the hills",
			mp3:"js/mediaplayer/sound/BeyondTheHills.mp3",
		},
		{
			//3. Deep sky meditation
			name:"3. Deep sky...",
			mp3:"js/mediaplayer/sound/DeepSkyMeditation.mp3",
		},
		{
			name:"4. Painting the ocean",
			mp3:"js/mediaplayer/sound/Robert Norton - PaintingTheOcean.mp3",
		},
		{
			name:"5. Second childhoods end",
			mp3:"js/mediaplayer/sound/SecondChildhoodsEnd.mp3",
		},
		{
			name:"6. Start of a new day",
			mp3:"js/mediaplayer/sound/StartOfANewDay.mp3",
		}
	
	], {
		ready: function() {
			audioPlaylist.displayPlaylist();
			//audioPlaylist.playlistInit(true); // Parameter is a boolean for autoplay.
		},
		ended: function() {
			audioPlaylist.playlistNext();
		},
		play: function() {
			$(this).jPlayer("pauseOthers");
		},
		swfPath: "js/mediaplayer/js",
		supplied: "mp3",
		volume: 0.05
	});
});



