startList = function() {
    if (document.all&&document.getElementById) {
        cssdropdownRoot = document.getElementById("cssdropdown");
        for (x=0; x<cssdropdownRoot.childNodes.length; x++) {
            node = cssdropdownRoot.childNodes[x];
            if (node.nodeName=="LI") {
                node.onmouseover=function() {
                    this.className+=" over";
                }
                node.onmouseout=function() {
                    this.className=this.className.replace(" over", "");
                }
            }
        }
    }
}

/*if (window.attachEvent){
    window.attachEvent("onload", startList)
}else{
    window.onload=startList;
}*/

$(document).ready(function() {
    //kawsar's---------------------------------------------------------------FarsiPraise
    $('input[type="checkbox"]').click(function() {
        $('span.track_price', $(this).parents('tr')).trigger('update_price');
    });
    
    $('input.selectall_inarow').livequery("click", function () {
        $('input[type="checkbox"]', $(this).parents('tr')).attr('checked', $(this).attr('checked'));
        $('span.track_price', $(this).parents('tr')).trigger('update_price');
    });
    
    $('img.selectall_inacol').click(function () {
        $('input.'+$(this).attr('media_type')+'').attr('checked', $(this).attr('checked'));
        
        if($(this).attr('checked') == 'checked'){
            $(this).attr('checked', '');
        }else{
            $(this).attr('checked', 'checked');
        }
        
        $('span.track_price').trigger('update_price');
    });
    
    $('a.select_all_track').click(function () {
        $('input[type="checkbox"]', $(this).parents('table')).attr('checked', $(this).attr('checked'));
        
        if($(this).attr('checked') == 'checked'){
            $(this).attr('checked', '');
        }else{
            $(this).attr('checked', 'checked');
        }
        
        $('span.track_price').trigger('update_price');
        return false;
    }).trigger('click');
    
    $('span.track_price').livequery("update_price", function () {
        var price = 0.00;
        $('input[type="checkbox"]', $(this).parents('tr')).each(function(i, e) {
            if($(e).attr('checked') && $(e).attr('unit_price')){
                price = (parseFloat(price) + parseFloat($(e).attr('unit_price')));
            }
        });
        $(this).html(price);
    }).trigger('update_price');
    
    //---------Advanced Search
    $('a.advanced').click(function() {
        $('div.advanced').toggle('slow');
        $(this).toggleClass('active');
        return false;
    });
    
    //----------------add to cart (buynow)
    
    $('form.buy.album,form.buy.song').ajaxForm({
        beforeSubmit: function() {
            $('div#body').prepend('<div class="message" id="loading">Loading...</div>');
        },
        success: function(data, b, form, d) {
            
            $('div#loading').html($('div.message', $(data)).html()).removeAttr('id');
            $('a#shopcart').text($('a#shopcart', $(data)).text());
            $('a#myshopcart').text($('a#myshopcart', $(data)).text());
            
            var succ = new RegExp("added successfully");
            if(succ.exec($('div.message', $(data)).text())){
                
                
                if($(form).hasClass('album')){
                    $(form).html('<img src="'+site.url+'/templates/images/album_added_'+site.lang+'.gif" />');
                }else{
                    $(form).html('<img src="'+site.url+'/templates/images/track_added_'+site.lang+'.gif" />');
                }
            }
        }
    });
    
    //------------------------------------------------------------------------------------FLOWPLAYER
    
    var playList = Array();
    $('a.play').each(function(i, e) {
        if(i == 0){
            playList[i] = {url: $(e).attr("href")};
        }else{
            playList[i] = {url: $(e).attr("href"), autoPlay: true};
        }
    });
    
    $('a.play_album').livequery('click', function() {
        if(playList){
            $f().play(playList);
        }
        return false;
    });
    
    $('a.play').livequery('click', function() {
        $f().play($(this).attr('href'))
        return false;
    });
    $('a.stop').livequery('click', function() {
        $f().stop();
        return false;
    });
    $('a.stop').livequery('switchToDefault', function() {
        $('img', this).attr('src', 'templates/images/play.gif');
        $(this).attr('class', 'play');
    });
    
    
    $('#player').flowplayer(site.url+"/scripts/flowplayer/flowplayer-3.1.5.swf", {
        wmode: 'opaque',
        clip : {
            autoPlay: false,
            autoBuffering: false,
            //duration: 30,//equal to demo track duration
            onBeforeBegin: function() {
                $('a#player').close();
            },
            onBegin: function(clip) {
                $('a.stop').trigger("switchToDefault");
                
                $('img', $('a[href="'+clip.url+'"]')).attr('src', 'templates/images/stop.gif');
                $('a[href="'+clip.url+'"]').attr('class', 'stop');
            },
            onPause: function() {
                $('a.stop').trigger("switchToDefault");
            },
            onFinish: function() {
                $('a.stop').trigger("switchToDefault");
            },
            onStop: function() {
                $('a.stop').trigger("switchToDefault");
            }
        },
        plugins: {
            audio: {
                url: 'flowplayer.audio-3.1.2.swf'
            },
            controls: {
                height: 0,
                all: false
                //playlist: true,
                //fullscreen: false
            }/*,
            visual: {
                //url: 'http://flowplayer-releases.s3.amazonaws.com/swf/flowplayer.audiovisual-3.1.0-dev.swf',
                url: site.url+'/scripts/flowplayer/flowplayer.audiovisual-3.1.0-dev.swf',
                width: '100%',
                height: '100%',
                bottom: 0,
                left: 0,
                followScreen: false
            }*/
        },
        canvas: {
            backgroundColor: '#FFFFFF',
            backgroundGradient: 'none'
        }
        
    });
    
    // 1px round corners

    $(document).ready(function($) {
        $.extend($.fn, {
            dot: function(bg, size) { return $(this).css({'background': bg || 'white', 'height': size || '1px', 'width': size || '1px', 'position': 'absolute'}); },
            tl: function(offset) { return $(this).css({'top': offset || '0', 'left': offset || '0'}); },
            tr: function(offset) { return $(this).css({'top': offset || '0', 'right': offset || '0'}); },
            bl: function(offset) { return $(this).css({'bottom': offset || '0', 'left': offset || '0'}); },
            br: function(offset) { return $(this).css({'bottom': offset || '0', 'right': offset || '0'}); },
            pbg: function() { var pbg = $(this).eq(0).parent().css('background-color'); return pbg && (pbg != 'transparent') ? pbg : $(this).parent().pbg(); }
        });
        
        var d = $("<span></span>");
        $(".round").livequery(function() {
            switch(true) {
                case $.browser.mozilla:
                    return $(this).css('-moz-border-radius', '2px');
                case $.browser.safari:
                    return $(this).css('-webkit-border-radius', '2px');
                case $.browser.msie:
                case $.browser.opera:
                    var cd = d.clone().dot($(this).pbg());
                    var os = ($(this).css('border-width') && $(this).css('border-width') != '0px') ? '-' + $(this).css('border-width') : null;
                    if(os) $(this).css('overflow', 'visible');
                    $(this).append(cd.clone().tl(os)).append(cd.clone().tr(os)).append(cd.clone().bl(os)).append(cd.clone().br(os));
            }
        });
    });

    
});



