$(document).ready(function() {


    function windowoptions (id) {
        var winwidth = $(window).width(); 
        var winheight = $(window).height();
        var bodyheight = $(document).height();
    }

    windowoptions (1);




    // We only want these styles applied when javascript is enabled

	
	
	
	



	
	// Initialize Advanced Galleriffic Gallery
	
	

    $("#selcat").live("click",function() {
        $(".categories-list").slideDown();
    });
    
    $("*").not(".categories-list,#selcat").click (function() {
        $(".categories-list").slideUp();
    });
    
    
        
    $("a.portfolio").live("click",function() {
        $(".menu-sub,#izb").hide();
        $("#menu-portfolio").slideDown();
        $(".menu a").removeClass("active");
        $(this).addClass("active");
        return false;
    });
    
    $("a.about-us").live("click",function() {
    
    $(".menu a").removeClass("active");
    $(this).addClass("active");
    $(".menu-sub,#izb").hide();
        $("#menu-about").slideDown();
        return false;
    });
    
    
    
        
    $("#selectab a").live("click",function() {

    });
    
    $('.album,.port-small,.text-inner').jScrollPane({
        scrollbarWidth:12,
        reinitialiseOnImageLoad: true

    });
	
    /*
	var gallery = $('#thumbs').galleriffic({
		delay:                     5000,
		numThumbs:                 150,
		preloadAhead:              10,
		enableTopPager:            false,
		enableBottomPager:         false,
		maxPagesToShow:            7,
		imageContainerSel:         '#slideshow',
		controlsContainerSel:      '#controls',
		captionContainerSel:       '#caption',
		loadingContainerSel:       '#loading',
		renderSSControls:          true,
		renderNavControls:         true,
		playLinkText:              '',
		pauseLinkText:             '',
		prevLinkText:              '',
		nextLinkText:              '',
		nextPageLinkText:          'Next &rsaquo;',
		prevPageLinkText:          '&lsaquo; Prev',
		enableHistory:             false,
		autoStart:                 false,
		syncTransitions:           true,
		defaultTransitionDuration: 900,
		onSlideChange:             function(prevIndex, nextIndex) {
			// 'this' refers to the gallery, which is an extension of $('#thumbs')
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onPageTransitionOut:       function(callback) {
			this.fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn:        function() {
			this.fadeTo('fast', 1.0);
		}
	});

	
	
		$("#sdrag").draggable({
        containment: 'parent',
        scroll: false,
        
        start: function () {
            //gallery.pause();
        },
        

        
        stop: function () {
            var pos = $(this).css("left");
            pos = str_replace("px","",pos);
            
            if (pos <= 12) {sec = 10;} 
            else if (pos > 12 && pos <= 24) {sec = 9;}
            else if (pos > 24 && pos <= 36) {sec = 8;}
            else if (pos > 36 && pos <= 48) {sec = 7; }
            else if (pos > 48 && pos <= 60) {sec = 6;}
            else if (pos > 60 && pos <= 72) {sec = 5;}
            else if (pos > 72 && pos <= 84) {sec = 4;}
            else if (pos > 84 && pos <= 96) {sec = 3;}
            else if (pos > 96 && pos <= 108) {sec = 2;}
            else if (pos > 108) {sec = 1;}

            $("#delay").html(sec+" sec.");
            
            var defa=sec*1000;
            $("#delayms").val(defa);
            gallery.delay=defa;
        }
        
        
        
    });
    
    $("#pplay").click(function() {
        gallery.play();
        $("#pstop").removeClass("active");
        $(this).addClass("active");
        return false;
        
    });
    
    $("#pstop").click(function() {
        gallery.pause();
        $("#pplay").removeClass("active");
        $(this).addClass("active");
        return false;
    });
  



*/




    $(".phg,.prev,.next").click(function() {
        $("#pplay").removeClass("active");
        $("#pstop").addClass("active");
    });






    $("#nextous").live("click",function() {
        var all = $("#phlist .rec").length;
        var now = $("#nowphoto").val();
        var index = $("#re"+now).index('#phlist a');
        var nowindex = index+1;
        if (nowindex>=all) {
            var newrel = $("#phlist a:first").attr("rel");
            var newhref= $("#phlist a:first").attr("href");
        } else {
            var newrel = $("#phlist a:eq("+nowindex+")").attr("rel");
            var newhref= $("#phlist a:eq("+nowindex+")").attr("href");
        }
        var now = $("#nowphoto").val(newrel);
        $(".imgvd").removeClass("viewed");
        $("#photov").append('<div class="imgvd viewed" style="display:none"><img src="'+newhref+'" /></div>');
        $(".imgvd").not(".viewed").fadeOut(600);
        $(".viewed").fadeIn(600,function() {
            $(".imgvd").not(".viewed").remove();
        });
        return false;
    });



    $("#prevous").live("click",function() {
        var all = $("#phlist .rec").length;
        var now = $("#nowphoto").val();
        var index = $("#re"+now).index('#phlist a');
        var baindex = index-1;
        if (index<=0) {
            var newrel = $("#phlist a:last").attr("rel");
            var newhref= $("#phlist a:last").attr("href");
        } else {
            var newrel = $("#phlist a:eq("+baindex+")").attr("rel");
            var newhref= $("#phlist a:eq("+baindex+")").attr("href");
        }
        var now = $("#nowphoto").val(newrel);
        $(".imgvd").removeClass("viewed");
        $("#photov").append('<div class="imgvd viewed" style="display:none"><img src="'+newhref+'" /></div>');
        $(".imgvd").not(".viewed").fadeOut(600);
        
        $(document).ready(function() {
            $(".viewed").fadeIn(600,function() {
                $(".imgvd").not(".viewed").remove();
            });
        });
        
        return false;
    });

    $("#closel").live("click",function() {
        $(".viewphoto").fadeOut();
        $("body").css("overflow","auto");
        return false;
    });
    
    
    
    
    




    $('.add-book[rel="notadded"]').live("click",function() {
        var thi = this;
        var rec = $(this).parents(".add").find("input").val();
        $.ajax({ url:"/guest/?A=1&type=add&rec="+rec, dataType: "json",
        success: function (data) {
            $("#favcount").html(data.content.favcount);
            $(thi).attr("rel","added");
        }});
        return false;
    });
    

    
    $('.add-book[rel="added"]').live("click",function() {
        var thi = this;
        var rec = $(this).parents(".add").find("input").val();
        $.ajax({ url:"/guest/?A=1&type=remove&rec="+rec, dataType: "json",
        success: function (data) {
            $("#favcount").html(data.content.favcount);
            $(thi).attr("rel","notadded");
        }});
        return false;
    });
    
    
    $(".dragg").draggable({
        containment: 'document',
        scroll:false
    });
    
    
    

    
    $("#audioplay").live("click",function() {
        $(".dragg").removeClass(".active");
        $("#audioplaycontent").slideToggle(); 
        $(this).toggleClass("active");   
        return false;
    });
    
    $("#audioplay2").live("click",function() {
        $(".dragg").removeClass(".active");
        $("#audioplaycontent2").slideToggle(); 
        $(this).toggleClass("active");   
        return false;
    });
    
    

});
AudioPlayer.setup("theme/base/swf/player.swf", {
	width: 83,
    transparentpagebg: "yes",
    noinfo: "yes",
    animation: "no",
    autostart: "yes"
});

