$(function()
{

	$.fn.ResSniffer = function(options)
	{
		var defaults = 	{
							newClass: "highres",
							breakHeight: 0,
							breakWidth: 0,
							matchBoth: true
						};
		options = $.extend(defaults, options);
		var sNewClass = options["newClass"];
		var iBrkHei = options["breakHeight"];
		var iBrkWid = options["breakWidth"];
		var bBoth = options["matchBoth"];
		$(this).removeClass(sNewClass);
		if((bBoth&&screen.width>=iBrkWid&&screen.height>=iBrkHei)||(!bBoth&&(screen.width>=iBrkWid||screen.height>=iBrkHei)))
		{
			$(this).addClass(sNewClass);
		}
	}
	
	$.fn.WindowSniffer = function(options)
	{
		var defaults = 	{
							newClass: "highres",
							breakHeight: 0,
							breakWidth: 0,
							matchBoth: true,
							onResize: false
						};
		options = $.extend(defaults, options);
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		var sNewClass = options["newClass"];
		var iBrkHei = options["breakHeight"];
		var iBrkWid = options["breakWidth"];
		var bBoth = options["matchBoth"];
		$(this).removeClass(sNewClass);
		if((bBoth&&myWidth>=iBrkWid&&myHeight>=iBrkHei)||(!bBoth&&(myWidth>=iBrkWid||myHeight>=iBrkHei)))
		{
			$this = $(this);
			$(this).addClass(sNewClass);
			$.ajax({
							url: "ajax/hiresgallery.html",
							cache: false,
							success: function(html){
									$this.html(html);
									
									var start = (Math.floor(Math.random()*$('#index-gallery .index-slide ').length)+1);
									
									$("#index-gallery").SlideStrip({
										cycleSlides: true,
										navBar: false,
										playWidth: 926,
										playHeight: 627,
										defaultSlide: start
									});
									$("#gallery .show-thumbs").click(function(){
										$(".thumbo").css("display","block");
										$(".thumbo").animate({height:154},500);
										return false;
									});
									$("#gallery .hide-thumbs").click(function(){
										$(".thumbo").animate({height:0},500,function() {$(".thumbo").css("display","none");});
										return false;
									});
									$("#thumbo-slide").SlideStripIndex({
										cycleSlides: true,
										navBar: false,
										playWidth: 94,
										playHeight: 62
									});
									$(".left, .larr a").css('display','block');
									$(".left, .larr a").cycleSlideGall({
										cycleSlides: true,
										slideRate: 1000,
										autoSlide: false,
										autoTimer: 5000,
										slideDir: "prevSlide"
									});
									$(".right, .rarr a").css('display','block');
									$(".right, .rarr a").cycleSlideGall({
										cycleSlides: true,
										slideRate: 1000,
										autoSlide: false,
										autoTimer: 5000,
										slideDir: "nextSlide"
									});
								}
							});
		}
		else
		{
			$this = $(this);
			$.ajax({
							url: "ajax/loresgallery.html",
							cache: false,
							success: function(html){
									$this.html(html);
								
									var start = (Math.floor(Math.random()*$('#index-gallery .index-slide ').length)+1);
									
									$("#index-gallery").SlideStrip({
										cycleSlides: true,
										navBar: false,
										playWidth: 926,
										playHeight: 627,
										defaultSlide: start
									});
									$("#gallery .show-thumbs").click(function(){
										$(".thumbo").css("display","block");
										$(".thumbo").animate({height:154},500);
										return false;
									});
									$("#gallery .hide-thumbs").click(function(){
										$(".thumbo").animate({height:0},500,function() {$(".thumbo").css("display","none");});
										return false;
									});
									$("#thumbo-slide").SlideStripIndex({
										cycleSlides: true,
										navBar: false,
										playWidth: 94,
										playHeight: 62
									});
									$(".left, .larr a").css('display','block');
									$(".left, .larr a").cycleSlideGall({
										cycleSlides: true,
										slideRate: 1000,
										autoSlide: false,
										autoTimer: 5000,
										slideDir: "prevSlide"
									});
									$(".right, .rarr a").css('display','block');
									$(".right, .rarr a").cycleSlideGall({
										cycleSlides: true,
										slideRate: 1000,
										autoSlide: false,
										autoTimer: 5000,
										slideDir: "nextSlide"
									});
								}
							});
		}
		var oThis = $(this);
		if(options["onResize"])
		{
			$(window).bind('resize', function() {
				oThis.WindowSniffer({
									newClass: sNewClass,
									breakHeight: iBrkHei,
									breakWidth: iBrkWid,
									matchBoth: bBoth,
									onResize: false
								});
			});
		}
	}

	$("#gallery").WindowSniffer({
								newClass: "highres",
								breakHeight: 768,
								breakWidth: 950,
								matchBoth: true,
								onResize: false
							});
							
});
