// Function to allow one JavaScript file to be included by another.
// Copyright (C) 2006-08 www.cryer.co.uk
function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + templatepath +'/js/'+ jsFile + '"></scr' + 'ipt>'); 
}

IncludeJavaScript('jquery.jmp3.js');
IncludeJavaScript('jquery.flash.js');
IncludeJavaScript('jquery.twitter.js');
IncludeJavaScript('cufon-yui.js');
IncludeJavaScript('fonts/tusj_700.font.js');
IncludeJavaScript('fonts/coolvetica_400.font.js');
IncludeJavaScript('fonts/xenofone_400.font.js');
IncludeJavaScript('fonts/roughtrad_400.font.js');
if (pageid == '430'){
//IncludeJavaScript('jquery-easing.js');
//IncludeJavaScript('hoverIntent.js');
//IncludeJavaScript('superfish.js');
//IncludeJavaScript('jquery.prettyPhoto.js');
//IncludeJavaScript('jquery-what-am-i.js');
//IncludeJavaScript('slider.js');
}
if (pageid == '116'){
}
if (pageid == '544'){
}


	if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1)) {
		document.write("<meta name=\"viewport\" content=\"width=device-width; user-scalable=yes; initial-scale=-0.1; maximum-scale=1.0;\"><link rel=\"stylesheet\" href=\"http://www.mattbudd.co.uk/wp-content/themes/mattbudd2010/css/iphone.css\" type=\"text/css\" media=\"screen, projection\" />");
	}
	document.write('<style type="text/css">body{display:none}</style>');
$(document).ready(function(){ 
						   
	extLinks();
	replaceHrTag();
	//styleSecondCol();
	//StripeTable();
	fadeContent();
	 
	 
   
	if (pageid == '616'){
		$(".mediawrap").css("opacity", 0.15);
	} 
	if (pageid == '605'){
		$(".mediawrap").css("opacity", 0.15);
	} 
	
	if (pageid == '430'){
		$("#featured").css("opacity", 0.3);
		$(".slider-pages").css("opacity", 0.3);
		if($.browser.msie){
		$("#featured img").css("opacity", 0.3);
		$(".slider-pages a").css("opacity", 0.3);
		}
		$(".mediawrap").css("opacity", 0.15);
	} 
	
	if (pageid == '116'){
		//$("#featured").css("opacity", 0.3);
		//$(".slider-pages").css("opacity", 0.3);
		$(".mediawrap").css("opacity", 0.1);
		//if($.browser.msie){
		//$("#featured img").css("opacity", 0.3);
		//$(".slider-pages a").css("opacity", 0.3);
		//}
	}  
	
   $('body').css('display','block');

	
	if(($("#shecomesaround").length > 0) || ($("#catchinaz").length > 0)){
		
		$("#shecomesaround").jmp3({
			filepath: "http://www.hotlinkfiles.com/files/2430566_7ce0w/shecomesaround.mp3",
			backcolor: "d9d9d9",
			forecolor: "282828",
			width: 150,
			showdownload: "false"

		});	
							
							
		$("#catchinaz").jmp3({
			filepath: "http://www.hotlinkfiles.com/files/2430522_wymrx/catchingaz.mp3",
			backcolor: "d9d9d9",
			forecolor: "282828",
			width: 150,
			showdownload: "false"
		});	

	}


	$('#webcam').flash({
    	src: 'http://www.ustream.tv/flash/live/800607',
    	width: 300,
    	height: 220,
		wmode: 'transparent',
        flashvars: { viewcount : true, autoplay : false }
	});

	$(".tweet").tweet({
    	username: "matthewbudd",
    	join_text: "auto",
    	count: 3,
    	auto_join_text_default: "I said,",
    	auto_join_text_ed: "I",
    	auto_join_text_ing: "I was",
    	auto_join_text_reply: "I replied to",
    	auto_join_text_url: "I've been checking out",
    	loading_text: "loading tweets..."
    });
	

$(".enter-name").val("Enter Name");
$(".enter-email").val("Enter Email Address");
$(".enter-message").val("Your Message");
$(".enter-captcha").val("Enter contents of the image");

$(".enter-name").focus(function(){
		if ($(this).val()=="Enter Name"){$(this).val("");$(this).css('color','#fff');}
	});
$(".enter-name").blur(function(){
		if ($(this).val()==""){$(this).val("Enter Name");$(this).css('color','#666');}
	});

$(".enter-email").focus(function(){
		if ($(this).val()=="Enter Email Address"){$(this).val("");$(this).css('color','#fff');}
	});
$(".enter-email").blur(function(){
		if ($(this).val()==""){$(this).val("Enter Email Address");$(this).css('color','#666');}
	});

$(".enter-message").focus(function(){
		if ($(this).val()=="Your Message"){$(this).val("");$(this).css('color','#fff');}
	});
$(".enter-message").blur(function(){
		if ($(this).val()==""){$(this).val("Your Message");$(this).css('color','#666');}
	});

$(".enter-captcha").focus(function(){
		if ($(this).val()=="Enter contents of the image"){$(this).val("");$(this).css('color','#fff');}
	});
$(".enter-captcha").blur(function(){
		if ($(this).val()==""){$(this).val("Enter contents of the image");$(this).css('color','#666');}
	});
	/*
	$("#gallery-portfolio").flickr({    
		api_key: 'cc1be5e465c0a041864511672fa6e8be', // [string]  equired, see http://www.flickr.com/services/api/misc.api_keys.html
		type: 'photoset',         // [string]  allowed values: 'photoset', 'search', default: 'flickr.photos.getRecent'
		photoset_id: '72157622626898434',  // [string]  required, for type=='photoset'  
		text: null,         // [string]    for type=='search' free text search
		user_id: null,      // [string]  for type=='search' search by user id
		group_id: null,     // [string]  for type=='search' search by group id
		tags: null,         // [string]  for type=='search' comma separated list
		tag_mode: 'any',    // [string]   for type=='search' allowed values: 'any' (OR), 'all' (AND)
		sort: 'relevance',  // [string]   for type=='search' allowed values: 'date-posted-asc', 'date-posted-desc', 'date-taken-asc', 'date-taken-desc', 'interestingness-desc', 'interestingness-asc', 'relevance'
		thumb_size: 's',    // [string]    allowed values: 's' (75x75), 't' (100x?), 'm' (240x?)
		size: null,         // [string]   allowed values: 'm' (240x?), 'b' (1024x?), 'o' (original), default: (500x?)
		per_page: 9,      // [integer]  allowed values: max of 500
		page: 1,            // [integer]   see paging notes
		attr: '',           // [string] optional, attributes applied to thumbnail <a> tag
		api_url: null,      // [string]  optional, custom url that returns flickr JSON or JSON-P 'photos' or 'photoset'
		params: '',         // [string] optional, custom arguments, see http://www.flickr.com/services/api/flickr.photos.search.html
		api_callback: '?',  // [string]   optional, custom callback in flickr JSON-P response
		callback: null     // [function]  optional, callback function applied to entire %lt;ul%gt;
        //litebox: true      // boolean, if true requires jquery.litebox.js
  
   
  	}); 

	


	
	$("#gallery-interests").flickr({    
		api_key: '6fc9efef6ddf13d75a9f083eb397d1de', // [string]  equired, see http://www.flickr.com/services/api/misc.api_keys.html
		type: 'photoset',         // [string]  allowed values: 'photoset', 'search', default: 'flickr.photos.getRecent'
		photoset_id: '72157617796248822',  // [string]  required, for type=='photoset'  
		text: null,         // [string]    for type=='search' free text search
		user_id: null,      // [string]  for type=='search' search by user id
		group_id: null,     // [string]  for type=='search' search by group id
		tags: null,         // [string]  for type=='search' comma separated list
		tag_mode: 'any',    // [string]   for type=='search' allowed values: 'any' (OR), 'all' (AND)
		sort: 'relevance',  // [string]   for type=='search' allowed values: 'date-posted-asc', 'date-posted-desc', 'date-taken-asc', 'date-taken-desc', 'interestingness-desc', 'interestingness-asc', 'relevance'
		thumb_size: 's',    // [string]    allowed values: 's' (75x75), 't' (100x?), 'm' (240x?)
		size: null,         // [string]   allowed values: 'm' (240x?), 'b' (1024x?), 'o' (original), default: (500x?)
		per_page: 9,      // [integer]  allowed values: max of 500
		page: 1,            // [integer]   see paging notes
		attr: '',           // [string] optional, attributes applied to thumbnail <a> tag
		api_url: null,      // [string]  optional, custom url that returns flickr JSON or JSON-P 'photos' or 'photoset'
		params: '',         // [string] optional, custom arguments, see http://www.flickr.com/services/api/flickr.photos.search.html
		api_callback: '?',  // [string]   optional, custom callback in flickr JSON-P response
		callback: null      // [function]  optional, callback function applied to entire %lt;ul%gt;
        //litebox: true      // boolean, if true requires jquery.litebox.js
  	}); 
*/

//alert(BrowserDetect.version);

  if ($.browser.mozilla || $.browser.safari || BrowserDetect.version != 6) {
	  
Cufon.replace('#topnav ul li a', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#main .left .leftbox h4', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#main .right h4', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#footerright h4', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#footerleft h4', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('.top-slide h2', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});

//Cufon.replace('#twitter_update_list li', { fontFamily: 'coolvetica',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#main .right .intro p', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#main .right .introinner p', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#main .right .pagetitle', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#main .right .archiveentry h1 a', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#main .right .archiveentry small', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});
Cufon.replace('#main .right #post-561 h2', { fontFamily: 'tusj',hover:true,hoverables:{strong:true,em:true,a:true}});


//Cufon.replace('#main .left h3');
  }
});
	
function extLinks(){
	$('a[rel^="external"]').click(function(){
		window.open(this.href);
		return false;
	});
}

function replaceHrTag(){	
	$("hr").wrap("<div class='divider2'></div>");
}

function StripeTable(){	// must include table plugin to use this function			
	$(".leftcol tr").mouseover(function(){
		$(this).addClass("over");
	}).mouseout(function(){
		$(this).removeClass("over");
	});
	$(".leftcol tr:even").addClass("alt");  
}

function styleSecondCol(){
    $('tr').each(function(){		  
		var count=1;
    	$('td').each(function(){
      		count++;
			//alert(count);
			if(count%2 != 0){ 
				$(this).addClass("txtright");
			}
    	})
    })
}


function addPrintLink(){
	// add print page link - since it can only work for JS, only add it for JS users
	$('#print') // create list item
    .addClass('print') //add relevant class to it
    .append('<a href="javascript:window.print();">Print this page</a>') //put in the link
    .insertBefore('li a.foo'); //add before the li item with link of class 'foo'
}



function fadeContent() {
	  
	$('.mediawrap').mouseover(function () {
        $(this).stop().animate({opacity:1}, {duration:500});
    }).mouseout(function () {
		var isUp = $(this).find('.up').is('.up');
		if(!isUp){
        $(this).stop().animate({opacity:0.15}, {duration:500});
		}
    });
	$('.mediawrap .showhide a').each(function () {
											   
	$(this).click(function () {
		if($('.up').length > 0){
        $(this).removeClass('up');
        $(this).text('keep it up');
		}else{
        $(this).addClass('up');
        $(this).text('fade it');
		}
		return false;
    });
	
											   });
	  
	  
	$('.portfolio').mouseover(function () {
        $('#featured').stop().animate({opacity:1}, {duration:500});
        $('.slider-pages').stop().animate({opacity:1}, {duration:500});
		if($.browser.msie){
        $('#featured img').stop().animate({opacity:1}, {duration:500});
        $('.slider-pages a').stop().animate({opacity:1}, {duration:500});}
    }).mouseout(function () {
        $('#featured').stop().animate({opacity:0.3}, {duration:500});
        $('.slider-pages').stop().animate({opacity:0.3}, {duration:500});
if($.browser.msie){
        $('#featured img').stop().animate({opacity:0.3}, {duration:500});
        $('.slider-pages a').stop().animate({opacity:0.3}, {duration:500});}
    });
	  
	  
	  
	  
	
	$('#sound').click(function () {
      if ($(this).parents('.mediawrap').css('opacity') == 0.1) {
        $(this).parents('.mediawrap').fadeTo("slow", 1);
      } else {
        $(this).parents('.mediawrap').fadeTo("fast", 0.1);
      }
    });
	
	/*
	$("#main .left h3").css("opacity", 0.5);
	*/
	
	/*
	$('#main .left h2 a').mouseover(function () {
        $("#main .left h3").animate({opacity:1}, {duration:500});
    }).mouseout(function () {
        $("#main .left h3").animate({opacity:0.5}, {duration:500});
    });
	*/
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
