/*	ChillBox Packed - Version 1.2.1 - jQuery Plug-in
	by Christopher Hill - http://www.chillwebdesigns.co.uk/
	Last Modification: 07/01/10
	
	For more information, visit: http://www.chillwebdesigns.co.uk/chillbox.html
	
	Licensed under the Creative Commons Attribution 3.0 Unported License - http://creativecommons.org/licenses/by/3.0/
	- Free for use in both personal and commercial projects
	- Attribution requires leaving author name, author link, and the license info intact
*/  
	// Settings for modification.
	var OLC  =       "#000"; // Overlay color (hex)
	var OLO  =         "90"; // Overlay opacity (0-100%)
	var FIOL =          250; // Overlay fade in time (milliseconds)
	var LTC	 =       "#fff"; // Loading text color (hex)
	var LTS	 =         "12"; // Loading text size (px)
	var LT	 = "Loading..."; // Loading div text
	var CBBC =       "transparent"; // ChillBox background color (hex)
	var CBTC =       "#fff"; // ChillBox title color (hex)
	var CBTS =         "12"; // ChillBox title text size 10-16 (px)
	var ECBC =		 "true"; // Enable ChillBox Group image counter
	var ST	 =       "true"; // ChillBox show all titles = true or hide all = false
	var BC   =       "transparent"; // ChillBox button color (hex)
	var BTC	 =       "#fff"; // ChillBox button text color (hex)
	var BTS	 =         "11"; // ChillBox button text size 10-16 (px)
	var BBC	 =       "transparent"; // ChillBox buttons border color (hex)
	var BBCH =    "transparent"; // ChillBox buttons hover border color (hex)
	var CLSB =          "X"; // ChillBox close button text
	var PREV =          "<"; // ChillBox prev button text
	var NEXT =          ">"; // ChillBox next button text
	var CBFI =          500; // ChillBox fade in time (milliseconds)
	var CBFO =          500; // ChillBox fade out time (milliseconds)
	var EKBB =		 "true"; // Enable the use of keyboard buttons = true or disable =false
	// Keys for close are x, X, c, C & ESC and for Next N, n, > Key and for Prev P, p, < Key
	var CBCC =       "false"; // Enable close ChillBox by clicking the ChillBox image
	var OLCC =       "true"; // Enable close ChillBox by clicking the overlay
	var LOOP =       "false"; // Enabled loop = true or disable loop = false

// No conflict, run everything as jQuery, this allows prototype framework to be used with the jQuery framework.	
(function($) {	

	// Onload start ChillBox.
	$(function(){
		doc = $(document);
win = $(window);
function preload(arrayOfImages) {
	$(arrayOfImages).each(function () {
		$('<img/>')[0].src = this
	})
}
var arr = $('a[rel^=ChillBox]').map(function (i, e) {
	return "'" + $(e).attr('href') + "'"
}).get().join(' , ');
preload(arr);
$('[rel=ChillBox]').click(function () {
	var hf = $(this).attr("href");
	var tit = $(this).attr("title");
	$('<div class="ChillBox"><img src="' + hf + '" /><a id="close">' + CLSB + '</a></div>').appendTo('body');
	$('<a id="close">' + CLSB + '</a></div>').appendTo('ov');
	if (ST == "true") {
		$('<span>' + tit + '</span>').appendTo('.ChillBox')
	}
	ChillBox();
	return false
});
$('[rel^=ChillBoxGroup]').click(function (index) {
	var rel = $(this).attr('rel');
	var relSize = $('[rel=' + rel + ']').size();
	var index = $('[rel=' + rel + ']').index(this);
	$(this).attr({
		'ChillBox-position': index
	});
	var hf = $(this).attr("href");
	var tit = $(this).attr("title");
	$('<div class="ChillBox"><img src="' + hf + '" /><a id="close">' + CLSB + '</a></div>').appendTo('body');
	if (ECBC == "true") {
			$('<span id="count">' + parseInt(index + 1) + ' /   ' + relSize + '</span>').appendTo('.ChillBox')
		}
	if ($('[rel=' + rel + ']').size() > 1) {
		$('<a id="next"><span>' + NEXT + '</span></a><a id="prev"><span>' + PREV + '</span></a>').appendTo('.ChillBox');
		if (ST == "true") {
		$('<span>' + tit + '</span>').appendTo('.ChillBox')
	}
		
		
	}
	if (CBCC == 'true') {
		$('.ChillBox img').click(function () {
			$('#close').click()
		})
	}
	$('[rel^=ChillBoxGroup]').filter('.selected').removeClass('selected');
	$(this).addClass('selected');
	var current = parseInt($('[rel^=ChillBoxGroup]').filter('.selected').attr('ChillBox-position'), 10);
	if (LOOP == "false") {
		if ($('[rel=' + rel + ']').last().hasClass('selected')) {
			$('#next').remove()
		}
		if ($('[rel=' + rel + ']').first().hasClass('selected')) {
			$('#prev').remove()
		}
	}
	if (EKBB == "true") {
		doc.keydown(function (e) {
			if (e.keyCode == 37 || e.keyCode == 80) {
				setTimeout(function () {
					$('#prev').click()
				},
				250)
			}
		});
		doc.keydown(function (e) {
			if (e.keyCode == 39 || e.keyCode == 78) {
				setTimeout(function () {
					$('#next').click()
				},
				250)
			}
		})
	}
	$('#prev').click(function () {
		$('.ChillBox').remove();
		setTimeout(function () {
			var to = $('[rel=' + rel + ']').eq(current - 1);
			if (!to.size()) {
				to = $('[rel=' + rel + ']').eq(0)
			}
			if (to.size()) {
				to.click()
			}
		},
		500);
		return false
	});
	$('#next').click(function () {
		$('.ChillBox').remove();
		setTimeout(function () {
			var too = $('[rel=' + rel + ']').eq(current + 1);
			if (!too.size()) {
				too = $('[rel=' + rel + ']').eq(0)
			}
			if (too.size()) {
				too.click()
			}
		},
		500);
		return false
	});
	ChillBox();
	return false
});
function ChillBox() {
	if ($('.Ov').is(':visible')) {
		var OLV = "true"
	}
	if (OLV != "true" || OLV == null) {
		Overlay(),
		Loading()
	};
	$(".ChillBox").css({
		opacity: '0',
		width: '0',
		bottom: '0',
		top: '0',
		right: '0',
		left: '0',
		height: '0',
		zIndex: '1003',
		fontFamily: 'DIN',
		backgroundColor: CBBC
	});
	$(".ChillBox img").load(function () {
		if ($().jquery >= "1.4.3") {
			var imgWidth = $('.ChillBox img').width();
			var imgHeight = $('.ChillBox img').height()
		} else {
			var imgWidth = jQuery.css(jQuery('.ChillBox img')[0], 'width');
			var imgHeight = jQuery.css(jQuery('.ChillBox img')[0], 'height')
		}
		if ($.browser.msie && $.browser.version <= 6 || navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
			win.scroll(function () {
				$(".ChillBox").css({
					top: win.scrollTop() + win.height() / 2 + "px"
				})
			});
			$(".ChillBox").css({
				position: 'absolute',
				left: '49.5%',
				top: win.scrollTop() + win.height() / 2 + "px",
				height: (imgHeight + 1) - imgHeight
			}).animate({
				opacity: "1",
				marginLeft: -(imgWidth / 2),
				marginTop: -(imgHeight / 2) - 15,
				width: (imgWidth + 22),
				height: (imgHeight + 46)
			},
			CBFI, function () {
				$(".ChillBox img,.ChillBox span,.ChillBox a").fadeTo(CBFI, '1')
			})
		} else {
			$(".ChillBox").css({
				position: 'fixed',
				top: '49.5%',
				left: '49.5%'
			}).animate({
				opacity: "1",
				marginLeft: -(imgWidth / 2),
				marginTop: -(imgHeight / 2) - 15,
				width: (imgWidth + 22),
				height: (imgHeight + 46)
			},
			CBFI, function () {
				$(".ChillBox img,.ChillBox span,").fadeTo(CBFI, '1')
			})
		}
		$(".ChillBox img").css({
			opacity: '0',
			margin: '12px 11px 5px 11px',
			padding: '0'
		});
		$(".ChillBox span").css({
			fontStyle: 'normal',
			backgroundColor: CBBC,
			color: CBTC,
			margin: '2px 11px',
		});
		$(".ChillBox span#count").css({
		});
		$(".ChillBox a#close").css({
			margin: '1px 11px 0px 4px',
			padding: '2px 5px'
		});
		$(".ChillBox a#close,.ChillBox a#next,.ChillBox a#prev").css({
			cursor: 'pointer',
			borderColor: BBC,
			textDecoration: 'none'
		});
		$(".ChillBox a#next,.ChillBox a#prev").css({
			margin: '1px 5px 0px 4px',
			padding: '2px 5px'
		});
		$(".ChillBox a#next,.ChillBox a#prev,.ChillBox a#close").hover(function () {
			$(this).css({
				border: '1px solid',
				borderColor: BBCH
			})
		},
		function () {
			$(".ChillBox a#next,.ChillBox a#prev,.ChillBox a#close").css({
				border: '1px solid',
				borderColor: BBC
			})
		});
		$('#close').click(function () {
			$(".ChillBox img,.ChillBox span,.ChillBox a,.Loading").remove();
			$('.Ov').fadeTo(CBFO, '0', function () {
				$('.Ov,.ChillBox').remove()
			});
			if ($.browser.msie && $.browser.version <= 6) {
				$(".ChillBox").animate({
					opacity: "0",
					left: '49.5%',
					top: $(window).scrollTop() + $(window).height() / 2 + "px",
					marginLeft: (imgWidth / 2),
					marginTop: (imgHeight / 2) - 15,
					width: -(imgWidth + 22),
					height: -(imgHeight + 46)
				},
				CBFO)
			} else {
				$(".ChillBox").animate({
					opacity: "0",
					left: '49.5%',
					top: '49.5%',
					marginLeft: (imgWidth / 2),
					marginTop: (imgHeight / 2) - 15,
					width: -(imgWidth + 22),
					height: -(imgHeight + 46)
				},
				CBFO)
			}
		});
		if (OLCC == 'true') {
			$('.Ov').click(function () {
				$('#close').click()
			});
			$('.Ov').hover().css({
				cursor: 'pointer'
			})
		}
		if (CBCC == 'true') {
			$('.ChillBox img').click(function () {
				$('#close').click()
			});
			$('.ChillBox img').hover().css({
				cursor: 'pointer'
			})
		}
		if (EKBB == "true") {
			doc.keypress(function (e) {
				if (e.keyCode == 120 || e.keyCode == 99) {
					$('#close').click()
				}
			});
			doc.keydown(function (e) {
				if (e.keyCode == 27 || e.keyCode == 88 || e.keyCode == 67) {
					$('#close').click()
				}
			})
		}
	})
}
function Overlay() {
	$('<div class="Ov"></div>').appendTo('body');
	$('.Ov').hide();
	ReposOv();
	win.resize(function () {
		ReposOv()
	});
	function ReposOv() {
		var winHeight = win.height();
		var winWidth = win.width();
		var pageHeight = doc.height();
		$('.Ov').css({
			backgroundColor: OLC,
			bottom: '0',
			right: '0',
			top: '0',
			left: '0',
			margin: '0',
			padding: '0',
			width: winWidth,
			zIndex: '1001'
		});
		if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
			$('.Ov').css({
				position: 'absolute',
				height: pageHeight
			})
		} else {
			if ($.browser.msie && $.browser.version <= 6) {
				$('.Ov').css({
					position: 'absolute',
					height: pageHeight - $('.ChillBox').height()
				})
			} else {
				$('.Ov').css({
					position: 'fixed',
					height: winHeight
				})
			}
		}
	}
	if (parseInt(OLO) <= '9') {
		$('.Ov').fadeTo(FIOL, "0.0" + OLO)
	} else {
		if (OLO >= '10' && OLO != '100') {
			$('.Ov').fadeTo(FIOL, "0." + OLO)
		} else {
			if (OLO == '100') {
				$('.Ov').fadeIn(FIOL)
			}
		}
	}
}
function Loading() {
	$('body').append('<div class="Loading">' + LT + '</div>');
	$('.Ov,.ChillBox,.Loading').bind("contextmenu", function (e) {
		return false
	});
	ReposLoad();
	win.resize(function () {
		ReposLoad()
	});
	function ReposLoad() {
		$('.Loading').css({
			fontFamily: 'DIN',
			width: '100px',
			bottom: '0',
			top: win.height() / 2,
			right: '0',
			fontSize: LTS + "px",
			textAlign: 'center',
			left: win.width() / 2 - 50,
			zIndex: '1002',
			height: '0',
			color: LTC,
			position: 'fixed'
		});
		if ($.browser.msie && $.browser.version <= 6 || navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
			$('.Loading').css({
				position: 'absolute',
				padding: '0',
				top: win.scrollTop() + win.height() / 2 + "px"
			});
			$(".ChillBox").css({
				top: win.scrollTop() + win.height() / 2 + "px"
			});
			win.scroll(function () {
				$(".Loading").css({
					top: win.scrollTop() + win.height() / 2 + "px"
				})
			})
		}
	}
}
	// End of document ready function
	});
	
// End of no conflict function
})(jQuery) 
