Cufon.replace('#Telephone, li.latest h2, .rounded header h1, .rounded header h2, .snipped header h1, .snipped header h2, #Twitter, .more-from-panes h2',{fontFamily: 'SchulbuchSued-Fett-ReplacedI'});

var titleHide = {
	
	init:function() {
		if($(window).width() < 660) {
			$("body.work section.some-more-work h1, article#Work section.more-work header h1").html('WORK');
			$("header#MainHeader nav ul li.shop").hide();	
		} else {
			$("body.work section.some-more-work h1, article#Work section.more-work header h1").html('SOME MORE WORK');
			$("header#MainHeader nav ul li.shop").show();
		}
	}
}

var shopHide = {
	
	init:function() {
		if($(window).width() < 660) {
			$("header#MainHeader nav ul li.shop").hide();	
		} else {
			$("header#MainHeader nav ul li.shop").show();
		}
	}
}

var productScroller = {
    
    init:function(){
        $(".scrollable").scrollable();  // initialize scrollable
    }
}

var someWorkScroller = {
	
    someWorkScrollables : null,
	
    init:function(){
		
        this.someWorkScrollables = $('div.more-from-panes').scrollable({
            vertical:true,
            easing: 'easeInOutExpo',
            speed:600
        });
    }
}

var workTabs = {

    Tabs : null,
    TabsApi : null,
    Panes : null,

    init:function(){
        this.Tabs = $("ul.tabs").tabs("div.panes > div",{history:true});		
        this.TabsApi = $("section.some-work ul.tabs").data("tabs");
		
        // ensure we have the right content in the vertical scroller
        someWorkScroller.someWorkScrollables.scrollable().seekTo(this.TabsApi.getIndex(),0);
        this.initClickListener();
    },

    initClickListener:function(){
        this.TabsApi.onClick(function(event,index){
            someWorkScroller.someWorkScrollables.scrollable().seekTo(index);
            $("div.panes div iframe").each(function(paneindex,element){
                if(paneindex != index)
                    $(this).get(0).api('api_pause');    // pause videos
            });
        });
    }
}

var homeTabs = {

    init:function(){
        this.Tabs = $("ul.tabs").tabs("div.panes > div");
        this.TabsApi = $("section.featured-work ul.tabs").data("tabs");
        this.initClickListener();
    },

    initClickListener:function(){
        this.TabsApi.onClick(function(event,index){
            $("div.panes div iframe").each(function(paneindex,element){
                if(paneindex != index-1)    // +1 since we've got 1 more tab than iframe
                    $(this).get(0).api('api_pause');    // pause videos
            });
        });
    }
}

var awardScroller = {

    awardsScrollable : null,
    awardsItems:null,

    init:function(){

        this.awardsItems = $(".awards .items");
        this.awardsScrollable = $(".awards .scrollable").scrollable({circular:true,speed:5000,easing:"linear"}).autoscroll({autopause:false});

        // fix for scrollable flicker
        this.awardsScrollable.each(function() {
            var $itemToAppend = $(this).scrollable().getItems().slice(1,2);
            var $itemToPrepend = $(this).scrollable().getItems().slice($(this).scrollable().getSize()-2,$(this).scrollable().getSize()-1);
            var $wrap = $(this).scrollable().getItemWrap();
            var clonedClass = $(this).scrollable().getConf().clonedClass;
            $itemToPrepend.clone(true).prependTo($wrap).addClass(clonedClass + ' hacked-' + clonedClass);
            $itemToAppend.clone(true).appendTo($wrap).addClass(clonedClass + ' hacked-' + clonedClass);
        });

        this.awardsScrollable.scrollable().onSeek(function(event,index){

            // fade out previous item (TODO - this is buggy on final item)
            $('.awards .items div:eq('+eval(index+1)+')').animate({opacity:0.5},500,function(){
                $('.awards .items div:eq('+eval(index+2)+')').animate({opacity:1},500); // fade in current item
            });

            $('.awards p.more-link span').fadeOut(500,function(){$(this).html($('.awards .items div:eq('+eval(index+2)+') span').html()).fadeIn(500);});
        });

        this.awardsScrollable.scrollable().seekTo(0,0);
        this.awardsItems.animate({opacity:1},500);
    }
}

var whoThumbs = {

    thumbImages:null,

    init:function(){
        
        this.thumbImages = $("#WhoThumbs dd.image img");

        this.thumbImages.mouseover(function(){
            $(this).stop(true,true).animate({opacity:0},500);
        });
        this.thumbImages.mouseout(function(){
            $(this).stop(true,true).animate({opacity:1},500);
        });

    }
}

var tweetLive = {
	
	init:function(){
		
		$('#Live .more-link a').click(function(){
			window.open(this.href,'twitWin','top='+(($(window).height()/2)-175)+',left='+(($(window).width()/2)-300)+',width=600,height=350');
			return false;
		});
	}
}

//$('body').ready(function() {
//	$('#Container').show();
//});
						
$(function(){

    if($('body.home').length){
        homeTabs.init();
        productScroller.init();
        $('#slideshow1').cycle();
//		tweetLive.init();
    }

    if($('body.work-index').length){
        someWorkScroller.init();
        workTabs.init();
        awardScroller.init();
    }
	
    if($('body.work-detail').length)
        projectScroller.initVideoPausing();

    if($('body.who').length)
        whoThumbs.init();

	if($('body.what div#WhatIsLOVEVideo').width() < 621) {
		$('body.what div#WhatIsLOVEVideo').css({height: "318px"});
		$('body.what div#WhatIsLOVEVideo iframe').attr('height', '325');	
	}
});
