    $(document).ready(function(){

jQuery.fn.extend({
    disableSelection : function() {
        this.each(function() {
                        // Safari/Chrome/Konqueror/Opera/Mozilla/ie
            this.onselectstart = function() { return false; };
            this.unselectable = "on";
            jQuery(this).css('-moz-user-select', 'none');
            jQuery(this).css('-webkit-user-select', 'none');
            jQuery(this).css('-khtml-user-select', 'none');
        });
    }
});


var main_url = window.location.href;
if(main_url == "http://www.giottoclub.dev.binn.ru/" || main_url == "http://giottoclub.dev.binn.ru/"){
$(".plDark").hide();
}


$('.sliderCont').disableSelection();

/*if(!jQuery.cookie('status')){
jQuery.cookie('status', '0', {path: "/"});
$("#playerControl").addClass('playerNoSound');
    $("#playerControl").attr('rel', '0');
}else{

url = window.location.href;
if(url.indexOf('/video') != '-1'){
    jQuery.cookie('status', '0', {path: "/"});
}*/


var typeOfFile = 'mp3';
if (jQuery.browser.opera){
typeOfFile = 'ogg';
}


if(!jQuery.cookie('status') || jQuery.cookie('status') && jQuery.cookie('status') == '0'){
    $("#playerControl").addClass('playerNoSound');
    $("#playerControl").attr('rel', '0');
}

if(jQuery.browser.mozilla || jQuery.browser.msie){
            flowplayer("audioP", "/flowplayer/flowplayer-3.2.7.swf", {
                plugins:{
                    audio: {url: '/flowplayer/flowplayer.audio-3.2.2.swf'}
                    },
                clip: {
                    url:'/mp3/ForGiotto.mp3',
                    autoPlay:false, 
                    autobuffering:true,
                     loop: true
                }
            });
            
            if(jQuery.cookie('time')){
                curTime = jQuery.cookie('time');
                //alert(curTime);
                $f(0).seek(curTime);
            }
            //seek(seconds)
} else {
    var audio = new Audio('http://www.giottoclub.dev.binn.ru/mp3/ForGiotto.' + typeOfFile);
    audio.loop = true;
}



if(/*!jQuery.cookie('status') || */(jQuery.cookie('status') && jQuery.cookie('status') == '1')){
if(jQuery.browser.mozilla || jQuery.browser.msie){
            //запуск
            $f(0).play();
} else {
        audio.play();
        
        if(jQuery.cookie('time')){
            curTime = jQuery.cookie('time');
            //alert(curTime);
            //audio.currentTime = curTime;
        }
    }
}

$("#playerControl").click(function(){
   var status = $(this).attr('rel');

        if(status == '1'){
            if(jQuery.browser.mozilla || jQuery.browser.msie){
                $(this).attr('rel', '0');
                $(this).addClass('playerNoSound');
                jQuery.cookie('status', '0', {path: "/"});
                $f(0).pause();
            } else {
                $(this).attr('rel', '0');
                $(this).addClass('playerNoSound');
                jQuery.cookie('status', '0', {path: "/"});

                audio.pause();
            }
        }
        else
        {
            if(jQuery.browser.mozilla || jQuery.browser.msie){
                
                $(this).attr('rel', '1');
                $(this).removeClass('playerNoSound');
                jQuery.cookie('status', '1', {path: "/"});
                $f(0).play();
                
            } else {
                $(this).attr('rel', '1');
                $(this).removeClass('playerNoSound');
                jQuery.cookie('status', '1', {path: "/"});

                audio.play();
            }
        }
        
        return false;
    });



$("a").click(function(){
curTime = 0;
if(jQuery.browser.mozilla || jQuery.browser.msie){
    curTime = $f(0).getTime();
} else {
    curTime = audio.currentTime;
}



jQuery.cookie('time', curTime, {path: "/"});
});



// Ipad scroll fix

var isiPad = navigator.userAgent.match(/iPad/i) != null;

if(isiPad) {
	//alert("IPAD");
} else {
	$(".menuList").jScrollPane();
}



//$(".menuList").jScrollPane();
//$('.plDark').addClass('collapsed');


$("#switchMenu").click(function(){

current = $(this).attr('rel');
if(current == '1'){
$(this).attr('rel', '0');
$(this).attr('title', 'Подробно');
$(this).text('подробно');
$('.plDark').addClass('collapsed', 800);
Cufon.refresh();

} else {
$(this).attr('rel', '1');
$(this).attr('title', 'Свернуть');
$(this).text('свернуть');
$('.plDark').removeClass('collapsed', 800);
$('.menuList').css({'height':'329px','width':'520px'});
//$('.jScrollPaneContainer').css({'height':'100%','width':'520px'});
Cufon.refresh();
}

return false;
});

$("#orderZ").removeClass("collapsed");


jQuery(".cusel").each( 
function(){ 
var w = parseInt(jQuery(this).width()), 
scrollPanel = jQuery(this).find(".cusel-scroll-pane"); 
if(w>=scrollPanel.width()) 
{ 
jQuery(this).find(".jScrollPaneContainer").width(w); 
scrollPanel.width(w); 
} 
}); 


var params = { 
changedEl: "#user_f_1", 
visRows: 10, 
scrollArrows: true 
} 
cuSel(params);


$(".withSub").mouseover(function(){
$(".withSub").removeClass('hover');
$(this).addClass('hover');

$(".withSub ul").hide();
$(this).find('ul').show();
});
$(".noSub").mouseover(function(){
$(".withSub").removeClass('hover');
$(".withSub ul").hide();
});

$("#headerInn, #middle").mouseover(function(){
$(".withSub").removeClass('hover');
$(".withSub ul").hide();
});
$("#headerInn, #middle").mouseover(function(){
$(".withSub").removeClass('hover');
$(".withSub ul").hide();
});
$(".withSub ul").mouseover(function(){
$(this).parent().addClass('hover');
$(this).parent().find("ul").show();
});




//Slider
bannerFlag = $(".forMain");
$(".sliderCont").prepend('<div class="pager_inn"><div class="pager"></div></div>');
if(bannerFlag.length > 0){
$('.slider').cycle({ 
fx:      'fade', 
speed:    1500, 
timeout:  5000,
pager: '.pager',
pause: 1,
activePagerClass: 'active',
onAfter:showScroll
});
}


bannerFlag = $(".forMain");
$(".sliderCont").prepend('<div class="pager_inn2"><div class="pager2"></div></div>');
if(bannerFlag.length > 0){
$('.slider2').cycle({ 
fx:      'fade',
speed:    10, 
timeout:  0,
pager: '.pager2',
activePagerClass: 'active'
});
}

var pwidth = $(".pager a").length * 29;
$(".pager_inn").css("width", pwidth);
$(".pager_inn").css("margin", "0px auto");


var pwidth2 = $(".pager2 a").length * 29;
$(".pager_inn2").css("width", pwidth2);
$(".pager_inn2").css("margin", "0px auto");


function showScroll(){
$(".responseDesc").jScrollPaneRemove();
$(".responseDesc").jScrollPane();
}


$("#dateField").datepicker({showOn: 'button', buttonImage: '/images/date.png', buttonImageOnly: true});


var mes = $(".sysMes").text();

if (mes != ''){
if ($.browser.msie && $.browser.version == 6) $("select").show();
$(".sysMes").dialog({
modal: true,
draggable: true,
resizable: false,
title: '',
width:450,
zIndex: 9999,
dialogClass: 'toLeft',
buttons: {
'Закрыть': function() {
$(this).dialog('close');
$(this).dialog("destroy");
if ($.browser.msie && $.browser.version == 6) $("select").show();
}
}

});
return false;
}


});
