jQuery(document).ready(function($) {
						   
  	//$('a[rel*=facebox]').facebox("Does this override");
	
	var d = new Date();
	var copyright = '&copy;'+(d.getYear()+1900)+' Binalogue.'
	
	
	
	//
	// Remove focus border onMouseUp without destroying usability.
	$("a").each(function(){$(this).onmouseup = $(this).blur();});
	
	
	if ($('.side_module').html()) {
		var output = '';
		jQuery.each($('.side_module'), function(i, val) {
			//alert(i+' | '+$(val).html());
			output += "<li>"+$(val).html()+"</li>";
      		//$("#" + this).text("My id is " + this + ".");
      		//return (this != "four"); // will stop running to skip "five"
    	});

		//$("#primary > ul li:eq(2)").parent().after(output);
		$("#primary > ul").prepend(output);
		$("#primary").show();
	}
	

	
	$('a[rel*=vpl-quicktime]').click(function () {
		var meta = $(this).attr("rel").split("|");
		var ref = meta[1];
		var w = meta[2];
		var h = Number(meta[3])+16;
		var html = '<div>';
		html +=	'	<object width="'+w+'" height="'+h+'" id="trailerMovie" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B">';
		html += '	<param value="http://www.binalogue.com/wp-content/uploads/'+ref+'" name="src"/>';
		html += '	<object width="'+w+'" height="'+h+'" type="video/quicktime" data="http://www.binalogue.com/wp-content/uploads/'+ref+'" id="trailerMovieInner" name="trailerMovie">';
		html += '		<param value="true" name="controller"/>';
		html += '		<param value="false" name="showlogo"/>';
		html += '		<param value="true" name="cache"/>';
		html += '		<param value="#000000" name="bgcolor"/>';
		html += '		<param value="true" name="autostart"/>';
		html += '		<param value="true" name="saveembedtags"/>';
		html += '		<param value="true" name="postdomevents"/>';
		html += '	</object>';
		html += '	<param value="true" name="controller"/>';
		html += '	<param value="false" name="showlogo"/>';
		html += '	<param value="true" name="cache"/>';
		html += '	<param value="#000000" name="bgcolor"/>';
		html += '	<param value="true" name="autostart"/>';
		html += '	<param value="true" name="saveembedtags"/>';
		html += '	<param value="true" name="postdomevents"/>';
		html += '	</object>';										  
		html += '	</div>';										  
      	jQuery.facebox(html);
		return false;
    });
	
	
	$('a[rel*=vpl-vimeo]').click(function () {
		var meta = $(this).attr("rel").split("|");
		var ref = meta[1];
		var w = meta[2];
		var h = meta[3];
		var html = '<div>';
		html +=	'	<object width="'+w+'" height="'+h+'">';
		html += '	<param name="allowfullscreen" value="true" />';
		html += '	<param name="allowscriptaccess" value="always" />';
		html += '	<param name="bgcolor" value="#000000" />';
		html += '	<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+ref+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ff6600&amp;fullscreen=1&amp;autoplay=1" />';
		html += '	<embed src="http://vimeo.com/moogaloop.swf?clip_id='+ref+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ff6600&amp;fullscreen=1&amp;autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+w+'" height="'+h+'" bgcolor="#000000"></embed>';	
		html += '	</object>';										  
		html += '	</div>';										  
      	jQuery.facebox(html);
		return false;
    });
	
	
	
	$('a[rel*=vpl-youtube]').click(function () {
		var meta = $(this).attr("rel").split("|");
		var ref = meta[1];
		var w = meta[2];
		var h = String(Number(meta[3])+25);
		var html = '<div>';
		html +=	'	<object width="'+w+'" height="'+h+'">';
		html +=	'		<param name="movie" value="http://www.youtube.com/v/'+ref+'&hl=en&fs=1&autoplay=1&ap=%2526fmt%3D18&hd=1"></param>';
		html +=	'		<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>';
		html +=	'		<embed src="http://www.youtube.com/v/'+ref+'&hl=en&fs=1&autoplay=1&ap=%2526fmt%3D18&hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+w+'" height="'+h+'"></embed>';
		html +=	'	</object>';
		html += '	</div>';										  
      	jQuery.facebox(html);
		return false;
    });
	
	
	
	
	
	
	



 	$('.boxgrid.caption').hover(function(){  
   		$(".cover", this).stop().animate({bottom:'-75%'},{queue:false,duration:160});  
    }, function() {  
    	$(".cover", this).stop().animate({bottom:'-100%'},{queue:false,duration:160});  
	});  
	
 	$('.boxgrid.gridview').hover(function(){  
   		$(".cover", this).stop().animate({bottom:'0px'},{queue:false,duration:160});  
    }, function() {  
    	$(".cover", this).stop().animate({bottom:'-170px'},{queue:false,duration:160});  
	});  
	
	
	
	
	
	/*
	
	$(".boxgrid img").imagetool({
		viewportWidth: 200,
		viewportHeight: 250,
		topX: 209,
		topY: 283,
		bottomX: 696,
		bottomY: 486,
		loading: "load.gif",
		callback: function(topX, topY, bottomX, bottomY) {     
			$("input.values").val("(" + topX + "," + topY + ")" + "(" + bottomX + "," + bottomY + ")");
		}
  	});
	
	*/
	


	// SIFR

if(typeof sIFR == "function"){
	// This is the preferred "named argument" syntax
	//sIFR.replaceElement(named({sSelector:"body h1", sFlashSrc:"/wp-content/themes/binalogue/assets/flash/isocpeur.swf", sColor:"#FF6600", sLinkColor:"#00ff00", sBgColor:"#000000", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:5, sFlashVars:"textalign=left&offsetTop=0"}));

};




	//
	// CONTACT FORM
	var applyHighlight = function () {
         $(this).addClass('focused');
    }
	var clearHighlight = function () {
         $(this).removeClass('focused');
    }
	
	$("input").focus(applyHighlight);
	$("textarea").focus(applyHighlight);
	$("input").blur(clearHighlight);
	$("textarea").blur(clearHighlight);








	$('a[rel*=iframebox]').click(function () {
		var attr = $(this).attr("rel").split("|");
		var w = attr[1];
		var h = attr[2];
		var ref = attr[3];
		var html = '<iframe width="'+w+'" height="'+h+'" frameborder="0" src="'+ref+'"/>';										  
		jQuery.facebox(html);
		
		$("div.caption").remove();
		var output = '<div class="caption">'+$(this).attr("title")+'<br />'+copyright+'</div>';
		$("div.footer").append(output);
		
		return false;
    });

	//
	// RESET ALL FACEBOX LINKS HREF ATTRIBUTE
	//$('a[rel*=vpl]').attr({ 
      //    href: "javascript:void(0);"
	//});	
	
	$('a[rel*=facebox]').facebox();
	
	$('a[rel*=facebox]').attr({ 
          href: "javascript:void(0);"
	});	
	//$('a[rel*=iframebox]').attr({ 
      //    href: "javascript:void(0);"
	//});	
	
	
	
	
	if ($.url.param("themeID").length) {
		var links = $('a');
		for (var i=0; i<links.length; i++) {
			var l = links[i];
			var href = $(l).attr('href');
			if ( (href.indexOf('themeID') == -1) && (href.indexOf('binalogue.com') != -1) ) {
				var pfx = (href.indexOf('?') == -1) ? '?' : '&';
				$(l).attr({href:href+pfx+'themeID='+$.url.param("themeID")});
			}
		}
	}
	
	
	
	var dollar = $;
	
		jQuery.each($('div[id*=flickr-]'), function(i, val) {
			var meta = $(this).attr("id").split("-");
			var id = meta[1];
			flickrLightbox(dollar, id);
    	});
	
	
	
	

});   










/* 
*  Lightbox/Squeezebox handlers
*/
function flickrLightbox($, setID){
	
	$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=43b45f50da9dc576452d565372c47bea&photoset_id="+setID+"&extras=url_sq,url_t,url_s,url_m,url_l,url_o&format=json&jsoncallback=?", function(data){
																																			  
		//$("#flickr-gallery-"+setID).append("<h2 class=\"entry-subtitle\">Project stills</h2>");
		
		//
		// EACH LOOP HANDLER
		$.each(data.photoset.photo, function(i,item){
			var imgURL = item.url_o;
			var desc = item.title;
			$("<img/>").attr({src: item.url_s, title: item.title, alt: item.title}).appendTo("#flickr-"+setID).wrap("<a href='" + imgURL + "' rel='lightbox-flickr-"+setID+"' title='"+desc+"<br />&copy;2009 Binalogue.'></a>");
		});
		
		//
		// DEFAULT LIGHTBOX BEHVAVIOUR
		$("a[rel^='lightbox']").slimbox({}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
				
	});

}

