// Wavestreaming.js
// (C) Copyright 2011 - Igniso Ltd, All Rights Reserved

$(function(){


    var videoon=0;

    $("#showvideo").click(function(){
    
        // alert("go");
        $("#videoPlayer").slideDown(); 
   
        jwplayer().play();

    
    });


    $("#stdcalc").submit(function(){
        var stdresult = (24 / $("#avglistentime").val()) * $("#servercapacity").val();
        $("#stdresult").html("<strong>Upto "+Math.floor(stdresult)+" Listeners Per Day</strong><br/>(Thats "+Math.floor(stdresult*30)+" per month!)");  
        return false;
    });



    $("#bwcalc").submit(function(){
    
        var KBPerHour = (($("#simlisteners").val() * 128) * 3600) / 8;
        var KBPeakShow = KBPerHour * $("#showlength").val();
        
        var bwresult = Math.floor(KBPeakShow / 1000000); // convert to GB
        
        $("#bwresult").html("<strong>You will use "+bwresult+"gb During Your Peak Show</strong><br/>(When you're broadcasting to "+$("#simlisteners").val()+" listeners at CD Quality - 128kbps)");  
        return false;
    });
    
    //placehodler stuff
    //simply set title attributes for placeholders
    (function(){
        var inputs = $('input[type=text]'),
        i=0,
        l=0;
        inputs.focus(function(){
            if(this.value === this.getAttribute('title')){
                this.value = '';
            }
        });
        inputs.blur(function(){
            if(this.value.length === 0){
                this.value = this.getAttribute('title');
            }
        });
        l = inputs.length;
        for(i=0;i<l;i+=1){
            if(inputs[i].value.length === 0){
                inputs[i].value = inputs[i].getAttribute('title');
            }
        }
    }());
    
    
    
    $("a.youtube").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'		: 680,
            'height'		: 410,
            'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/')+"&hd=1",
            'type'			: 'swf',
            'swf'			: {
                'wmode'		: 'transparent',
                'allowfullscreen'	: 'true'
            }
        });
        return false;
    });

    $("a.video").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'		: 680,
            'height'		: 410,
            'href'			: "http://stardust.wavestreamer.com/stevejamesvideo/jwplayer/player.swf?autostart=true&skin=http://stardust.wavestreamer.com/stevejamesvideo/jwplayer/glow.zip&file="+this.href,
            'type'			: 'swf',
            'swf'			: {
                'wmode'		: 'transparent',
                'allowfullscreen'	: 'true'
            }
        });
        return false;
    });

    $("a.box").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'		: this.title,
            'width'		: 500,
            'height'		: 400,
            'href'		: this.href,
            'type'		: 'iframe'
    
        });
        return false;
    });

    jcps.fader(300, '#switcher-panel');


    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) {
            return;
        }
        js = d.createElement(s);
        js.id = id;
        js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=109602199135000";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    
    
    $(function(){
        
        var packages = [
            [500,1000,2000,5000,7000,10000,15000,25000,50000,100000],
            [10,15,20,25,30,35,40,50,75,100],
            [146,147,167,149,150,151,152,153,154,155,156]
            
           // https://www.wavestreaming.com/clients/admin/configproducts.php?action=edit&id=147
          
        ],
        hdds = $('#opts').find('li'),
        sliderHandle,cost = $('#cost'), tracks = $('#tracks'),
        change = function(v){
            var i=0,o=1,storage;
            
            storage = packages[0][v];
            tracks.text(parseInt(storage/4,10));
            
            if(storage < 1000){
                storage += 'mb';
                
            }else{
                storage = (storage/1000)+'gb';
                
            }
            
            sliderHandle.text(storage);
            $("#diskspace").text(storage);
            $("#cdjorderlink").attr("href","https://www.wavestreaming.com/clients/cart.php?a=add&pid="+packages[2][v])
            cost.text("$"+packages[1][v]);
            for(i;i<10;i+=1){
                o = i <= v ? 1 : 0.4;
                $(hdds[i]).fadeTo('fast',o);
            }
        },
        sldr = $('#sld').slider({
            range: "min",
            animate: true,
            value: 0,
            min: 0,
            max: 9,
            slide: function(event, ui) {
                change(ui.value);
            }
        });
        sliderHandle =  $('.ui-slider-handle').text(packages[0][0]+'mb');
        hdds.click(function(){
            var pos = parseInt(this.getAttribute('rel'),10);
            sldr.slider('value',pos);
            change(pos);
        })
        $(hdds[4]).click();
     });
// end
});


        


