﻿/**
* Getting selected parameter's value from url
* 
* @param {String} param
* @return mixed(string|bool)
*/
function getUrlParam(param) {
    var queryString = window.location.href.substr(window.location.href.indexOf('?') + 1);
    var params = queryString.split('&');
    var tmp;

    for (var i = 0; i < params.length; i++) {
        tmp = params[i].split('=');
        if (tmp[0] == param) return tmp[1];
    }
    return false;
}

/**
* Function running by flash, when sound samples are loaded
*
* @return void
*/
function setLoaded() {
    var textFromGet = getUrlParam('txt');
    if (textFromGet) $('.title').val(unescape(textFromGet));
}

/**
* Flash comunicate javascript if anthem is end
* 
* @return void
*/
function endSong() {
    $(".btStop").hide();
    $(".btPlay").show();
}

/**
 * Drum controler helper
 * 
 * @return void
 */
function drumControlHelper() {

    var __this = this;

    __this.playDrum = function (element, text) {
        var obj = document.getElementById(element);
        if (text) {
        	if(obj) obj.startSong(text);
        } else {
        	if(obj) obj.startSong();
        }
    };

    __this.stopDrum = function (element) {
        var obj = document.getElementById(element);
        if(obj) obj.stopSong();
    };

}

/**
 * Play drum with anthem
 * 
 * @return boolean
 */
function playDrumAnthem() {

	var textToPlay = '';
	
	if( $(".play.box2:visible").length != 0 ){
		var chi = $(".play.box2 .title").children();
		textToPlay = chi.text();
	}
	if( $(".play.box3:visible").length != 0 ){
		textToPlay = $(".play.box3 .bgTitle input").val();
	}
	
    textToPlay = Pklib.Utils.trim(textToPlay);
            
    if (textToPlay == '') return false;

    var drum = new drumControlHelper();
    drum.playDrum('playerAnthemFlash', textToPlay);

    $('.btPlay').hide();
    $('.btStop').bind('click', function () {
        stopDrumAnthem();
        return false;
    }).show();

    return false;
}

/**
 * Stop drum with anthem
 * 
 * @return void
 */
function stopDrumAnthem() {

    var drum = new drumControlHelper();
    drum.stopDrum("playerAnthemFlash");

    $(".btStop").hide();
    $(".btPlay").show();

}

/**
 * Select all text in area by clicked
 * 
 * @return void
 */
function selectClickTestInArea(area) {
	if(area == undefined || area == '' || area == null ) return;
	$(area).bind('click', function(){
		$(this).focus().select();
	});
}
