$.noConflict();
jQuery(document).ready(function($) {

	function onAfter(curr,next,opts) {
		var caption = '<span class="slide-bg"></span>' + (opts.currSlide + 1) + '<span class="primer italic of lt-grey">of</span>' + opts.slideCount + '<span class="slide-bg"></span>';
		$('#number').html(caption);
	}
	
	function onAfterz(curr,next,opts) {
		var caption = '' + (opts.currSlide + 1) + '<span class="primer italic of lt-grey">of</span>' + opts.slideCount;
		$('#number').html(caption);
		var index = opts.currSlide;
        $('#prev')[index == 0 ? 'hide' : 'show']();
        $('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	}
	
	$('#accordion').accordion({
		collapsible: true,
		active: false
	});
	
	$("a.fade").mouseenter(function () {
		$("img", this).fadeTo(200, 0.7);		
	});
	
	$("a.fade").mouseleave(function () {
		$("img", this).fadeTo(150, 1);
	});
	
	// Gallery Cycle
	$('#gallery-cycle').cycle({ 
    fx:     'fade', 
    speed:  1000,
    sync: 1, 
    timeout: 0,
    next:   '#next', 
    prev:   '#prev',
    after: onAfter,
    pager:  '#gallery-thumbs-list', 
    pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#gallery-thumbs-list li:eq(' + idx + ') a'; 
    }
    });
    
    // Explore Cycle
	$('#explore-cycle').cycle({ 
    fx:     'fade', 
    speed:  1000,
    sync: 1, 
    timeout: 0,
    next:   '#next', 
    prev:   '#prev',
    nowrap: 1,
    cleartypeNoBg: true,
    after: onAfterz    
    });
    
    // Home Cycle
	$('#home-cycle').cycle({ 
    fx:     'fade', 
    speed:  1000,
    sync: 1, 
    timeout: 5000,
    next:   '#next-home', 
    prev:   '#prev-home'
    });
    
    // Mel Cycle
	$('.mel-cycle').cycle({ 
    fx:     'fade', 
    speed:  1000,
    sync: 1, 
    timeout: 5000
    });
    
    $("a.show-thumbs").click( function () { $('#gallery-thumbs').fadeToggle(400); });
    
    $("ul#gallery-thumbs-list li a").click( function () { $('#gallery-thumbs').fadeToggle(400); });
    
    $("a#next").click( function () { $('#gallery-thumbs').fadeOut(400); });
    
    $("a#prev").click( function () { $('#gallery-thumbs').fadeOut(400); });
    
    if ($.browser.webkit) {
    $height = 200
 	} else {
 	$height = $("#blog-sidebar").outerHeight() 
 	}
    
            
    $("#blog-sidebar").scrollToFixed({
        limit: $(".footer-top").offset().top - $height - 40,
        zIndex: 999,
        preFixed: function() { $(this).css("display", "block"); },
        preAbsolute: function() { $(this).css("display", "none"); }
    });
    
    $("a.back-to-top").click(function() {
      $("html, body").animate({ scrollTop:0 }, '1000');
	});

    
     $('.top-nav li').hover(
		function () {
			//show its submenu
			$('ul', this).fadeIn(200);
		}, 
		function () {
			//hide its submenu
			$('ul', this).fadeOut(200);			
		}
	);
	
	$('a.post-share').hover(
		function () {
			//show its submenu
			$('ul', this).fadeIn(200);
		}, 
		function () {
			//hide its submenu
			$('ul', this).fadeOut(200);			
		}
	);
	
	
	
	$('.home-slides').hover(
        function() { $('.controls a').fadeIn(); },
        function() { $('.controls a').fadeOut(); }
    );
    
    $('#gallery-cycle').waitForImages(function() {
    	$('.gallery-landing-right a.gallery-single').fadeToggle(500);
    	$('.gallery-landing-left .gallery-hide').fadeToggle(500);
    	$('.gallery-landing-left .pro-block').fadeToggle(500);
    	$('.gallery-landing-left .pro-block').addClass("loaded");
	});
	
	$(document).bind("contextmenu",function(e){
            return false;
    });
	
});

jQuery(window).scroll(function() {
    if (jQuery(this).scrollTop() >= 200) {
        jQuery("a.back-to-top").fadeIn();
    }
    else {
        jQuery("a.back-to-top").fadeOut();
    }
});



























