/*Define three t namespace*/
site = { };

/**********************************
* Begin Cufon
**********************************/
//Font
//Cufon.set('fontFamily', '');
Cufon.replace('#nav a', {hover: {color: '#DCB30F'}});
Cufon.replace("h1, h2, h3, #nav ul li, #header-right, #hero .slide-text span, #hero2 .slide div span, .answers_list LI SPAN, .slide h4", {fontFamily:"Dirty Headline"});
Cufon.replace(".button", {fontFamily:"Helvetica LT Std"});

/**********************************
* End Cufon
**********************************/


/**********************************
* Begin Cornerz
**********************************/
site.rounded_corners =
{
	init : function()
	{
		// Return if it doesn't look like cornerz has been loaded into jquery
		try 
        {
            (!$.fn.cornerz)
			return;
        }catch(err){
        
        }
            
		var activate = false;

		// TODO: This will require expanding for other browsers that need cornerz
		if (navigator.appName=="Microsoft Internet Explorer")
			activate = parseInt(navigator.appVersion) <= 8;

		if (activate)
			tfc.rounded_corners.apply_styles();
	},

	// NB styles will not be applied to anything with a .no-cornerz class assigned.
	apply_styles : function()
	{
		$('.rounded-button').not('.no-cornerz').cornerz({radius:6, background:'#3D768C'});
		$('.rounded-box').not('.no-cornerz').cornerz({radius:10, background:'#3D768C'});
	}
}


/**********************************
* Dom Ready
**********************************/
$(function()
{
	site.rounded_corners.init();
    
    // Homepage Hero number 2
    if($('#hero2').length) {
    
        $('#hero2').cycle({
            fx:     'scrollHorz',
            speed:  'slow',
            timeout: 0, // Don't auto slide
            pager:  '#hero2-nav',
            activePagerClass: 'active',
            next: '#hero2-next',
            prev: '#hero2-prev',
            pagerAnchorBuilder: function(index) {
                $("#hero2-nav .section:eq("+index+")").bind("click", function()
                {
                    $("#hero2").cycle(index);
                    return false;
                });
            }
        });
    }
    
    // Make all external links open in new window
    $('a:not([href=""])').each(function() 
    {
        if($(this).attr("href")) {
            if ((this.hostname !== location.hostname) && (($(this).attr("href").substr(0, 7) == 'http://') || ($(this).attr("href").substr(0, 8) == 'https://'))) // Check HTTP request type to avoid clashes with JS calls
            {
                $(this).bind("click", function()
                {
                    window.open($(this).attr("href"));
                    return false;
                });
            }
        }
    });
    
});


/***********************
* CHRIS JS -  Video Slideshow...
************************/

var slide = {
    
    slideDiv: '#slide',
    slideWidth: 570,
    thumbDiv: '.video-slide',
    animRunning: 0,
    animSpeed: 600,
    
    init: function() 
    {
        // Set slide width
        var slideDivAmount = $('#slide').children().size();
        var slideDivWidth = Math.ceil(slideDivAmount / 3) * 570;
        $('#slide').css('width', slideDivWidth + 'px');
        
        // Render the slide
        slide.render();
        
        $('#hero-videos-prev').bind({
            click: function() {
                slide.shift('right');
            }
        });
        $('#hero-videos-next').bind({
            click: function() {
                slide.shift('left');
            }
        });
    },
    
    // Shift div Left or Right
    shift: function(str) 
    {
        if(slide.animRunning == 0) 
        {
            var divPos = $(slide.slideDiv).css('left');
            var divWidth = $(slide.slideDiv).css('width');   

            // set animation running
            slide.animRunning = 1;
            
            // shift left or right?
            switch(str) 
            {
                case 'left':          
                   $(slide.slideDiv).animate({
                        'left': parseInt(divPos) - slide.slideWidth + 'px'
                    }, slide.animSpeed, function() 
                    {
                        slide.render();
                    });
                   break;
                    
                case 'right':
                    $(slide.slideDiv).animate({
                        'left': parseInt(divPos) + slide.slideWidth + 'px'
                     }, slide.animSpeed, function()
                     {
                        slide.render();
                     });
                    break;
            }
        }else{
            return false;
        }
    },
    
    // Render the arrows to dissappear
    render: function() {
       var p = $(slide.thumbDiv);
       var divPos = $(slide.slideDiv).css('left');
       var divWidth = $(slide.slideDiv).css('width'); 
       
       // show hide arrows - could be tidied perhaps...
       if(parseInt(divPos) == 0) 
       {
            $('#hero-videos-prev').css('display', 'none');
       }else{
            $('#hero-videos-prev').css('display', 'block');
       }
       if(Math.abs(parseInt(divPos)) + slide.slideWidth >= parseInt(divWidth)) 
       {
            $('#hero-videos-next').css('display', 'none');
       }else{
            $('#hero-videos-next').css('display', 'block');
       }
       slide.animRunning = 0;
    }
}

/***********************
* CHRIS JS -  Adding binds to image and video Page
************************/



var videoPage = {

    init: function()
    {
        if($('.image-box'))
        {
            // Set binds on links to load other images into large viewer
            $('.video-slide a').bind('click', function(e) 
            {   
                e.preventDefault();
                var video = $(this).attr("id");
                $('.image-large IFRAME').attr("src", 'http://www.youtube.com/embed/' + video);
                return false;
            });
        }
    }
}

/***********************
* CHRIS JS - TWITTER REQUESTS
************************/

var twitter = {
        
        URL: 'http://api.twitter.com/1/statuses/user_timeline.json',
        COUNT: '1',
        NAME: 'paintballnorth',
        
        init: function() 
        {
            twitter.getTweets();
        },
        
        // Make tweet Request
		getTweets: function() 
        {	
            jQuery.ajax({
                url: twitter.URL + '?count=' + twitter.COUNT + '&screen_name=' + twitter.NAME,
                dataType: 'jsonp',
                success: twitter.buildTweets
            });
		},
        
        // Build the list from Tweets
        buildTweets: function(data)
        {
            jQuery.each(data, function(k, v) {
                $('#twitter_update_list').append(v.text.replace(twitter.NAME + ':', ''));
            });
        }
	}
    
    
/***********************
* CHRIS JS - GOOGLE MAP REQUESTS
************************/
    
    
var Maps = {
    
    loadMap: function()
    {
        var pos = new google.maps.LatLng(54.84378, -1.40361);
        var myOptions = {
            zoom: 9,
            center: pos,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("gmap"), myOptions);
        var marker = new google.maps.Marker({
              position: pos,
              map: map,
              title: "Massive Attack Paintball"
        });
    }
}
