/**
 * Written by Andrew Timonin (http://www.impsite.com)
 * Date: 2009/12/15
 *
 * @author Andrew Timonin
 * @version 1.0
 *
 **/

function randomXToY(minVal,maxVal) {
    var randVal = minVal+(Math.random()*(maxVal-minVal));
    return Math.round(randVal);
}

function playListConfig( index ) {
    playItem = index;
    currentSong = index;
    jQuery("#jquery_jplayer").setFile(playList[playItem].mp3);
    jQuery("#music_name").text(playList[playItem].name);    
}

function playListChange( index ) {
    playListConfig(index);
    if(playerPaused == false) {
        playerPlay();
    }
}

function playerPlay() {
    jQuery("#jquery_jplayer").play();
    jQuery("#music_play").hide();
    jQuery("#music_pause").show();
    playerPaused = false;
}

function playerPause() {
    jQuery("#jquery_jplayer").pause();
    jQuery("#music_pause").hide();
    jQuery("#music_play").show();
    playerPaused = true;
}

function playerNext() {
    var index = currentSong;
    while (index == currentSong) {
        index = randomXToY(0, playList.length);
    }
    playListChange( index );
    jQuery("#music_progressbar").width("0%");
}

function playerPrev() {
    var index = currentSong;
    while (index == currentSong) {
        index = randomXToY(0, playList.length);
    }
    playListChange( index );
    jQuery("#music_progressbar").width("0%");
}


jQuery(document).ready(function() {
    //Placeholder
    jQuery("input:text").placeholder({'blankSubmit': true});
    jQuery("textarea").placeholder({'blankSubmit': true});

    //Tabs
    jQuery("div.div_tab a").click(function() {
        jQuery(this).parent().parent()
        .find("div.single_block_content").hide().end()
        .find("div."+jQuery(this).attr("rel")).show().end()
        .find("div.div_tab a").removeClass("selected");
        jQuery(this).addClass("selected");
        return false;
    });

     
    //Odri popup
    var flash_object = jQuery("div.top_banner div.banner object");
    jQuery("a.header_odri_photos").fancybox({
        'hideOnOverlayClick' : true,
        'overlayShow' : true,
        'overlayOpacity' : 0.8,
        'overlayColor' : '#fff',
        'enableEscapeButton' : true,
        'transitionIn'	: 'elastic',
	'transitionOut'	: 'elastic',
        'onStart' : function() {flash_object.css("visibility", "hidden");},
        'onClosed' : function() {flash_object.css("visibility", "visible");}
    });
});
