$(document).ready(function(){
	$('.clicknclear').click(function() {
		$(this).attr('rel', $(this).val());
		$(this).val('');
	}).blur(function() {
		if ($(this).val().length < 1)
			$(this).val($(this).attr('rel'));
	});
	
	// Expandable content areas
	$('.expand-content').hide();
	$('#contract-link').hide();
	$('#expand-link').click(function (e) {
		e.preventDefault();
		$('.expand-content').slideDown("slow");
		$('#expand-link').hide();
		$('#contract-link').show();
	});
	$('#contract-link').click(function (e) {
		e.preventDefault();
		$('.expand-content').slideUp();
		$('#contract-link').hide();
		$('#expand-link').show();
	});

	$(".printme").click(function () {
		window.print();
		return false;
	});
	
	$(".closeme").click(function () {
		window.close();
		return false;
	});

	if (typeof jQuery.fn.popupwindow == 'function') {
		$('.popupwindow').attr('rel', 'popupwindow').popupwindow({popupwindow: {height: 600, width:750, createnew:0, scrollbars:1, center:1}});
	}
	
	if (typeof jQuery.fn.ckeditor == 'function')
	{
		$('textarea.editor').ckeditor(function() { }, {
			format_tags: 'p;h2;h3;h4;h5;h6;pre;div',
            contentsCss: '/skin/css/ckeditor.css',
			toolbar: [
			  ['Format', 'Bold','Italic','Underline','StrikeThrough', 'BulletedList', 'NumberedList', 'Undo', 'Redo'],
			  ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
			  ['Link','Unlink','Table']
			]
		});
	}
	
	// FANCYBOX - Gallery
	if (typeof jQuery.fn.fancybox == 'function') {
		$('a.gallery-item').fancybox({
			'overlayOpacity': 0.7,
			'overlayColor':		'#000',
			'titlePosition'		: 'over'
		});
	}
	
	if (typeof Boxy == 'function') {
		$('#download-portfolio').click(function () {
			var url = $(this).attr('href');
			var initBoxy = Boxy.load(url, {
				title: 'Download Portfolio',
				draggable: false,
				modal: true,
				behaviours: function(c) {
					c.find('#subscribe-form').submit(function () {
						var b = Boxy.get(this).setContent('<div id="dialog-progress">One Moment ...</p>');
						$.post(url, { 'confirm':1, 'email': c.find('#email').val() }, function(data) {
							b.setContent(data);
						});
						return false;
					});
				}
			});
			return false;
		});
	}
});

