
jQuery(document).ready(function()
{
	/*var userAgent = navigator.userAgent.toLowerCase();
	var version = 0;
	
	// Is this a version of IE?
	if(jQuery.browser.msie)
	{
		userAgent = jQuery.browser.version;
		userAgent = userAgent.substring(0,userAgent.indexOf('.'));
		version = userAgent;
		jQuery('#browser-error').html('The browser you are using is not fully compatible with this website. For a better experience use Firefox or download a newer version of Internet Explorer.').show();
	}*/
	
	// Vertical dropdown
	jQuery('.vnav').find('li').each(function()
	{
		jQuery(this).hover(function()
		{
			var menu = jQuery(this).children('ul');
			jQuery(menu).css('left', jQuery(this).width());
			jQuery(menu).css('top', '0');
			jQuery(menu).show();
		}, function()
		{
			jQuery(this).children('ul').hide();
		});
	});
	
	// Horizontal dropdown
	jQuery('.hnav').children('ul').children('li').each(function()
	{
		jQuery(this).hover(function()
		{
			var menu = jQuery(this).children('ul');
			jQuery(menu).css('top', jQuery(this).height());
			jQuery(menu).slideDown(200);
			
			jQuery(menu).children('li').each(function()
			{
				jQuery(this).hover(function()
				{
					var menu2 = jQuery(this).children('ul');
					jQuery(menu2).css('left', jQuery(this).width());
					jQuery(menu2).css('top', '0');
					jQuery(menu2).show(); 
			
				}, function()
				{
					jQuery(this).children('ul').hide();
				});
			});
			
		}, function()
		{
			jQuery(this).children('ul').hide();
		});
	});
	
	// Entry List Caption DropDown
	jQuery('.entry').mouseenter(function () {jQuery(this).find('div.caption').delay(200).slideDown(250)});
	jQuery('.entry').mouseleave(function () {jQuery(this).find('div.caption').stop(true, true).slideUp(150)});
	
	jQuery('#s').labelify({ labelledClass: 'label-highlight' });
	
	
	/* Modal Popup Window
	----------------------*/
	// Create and append the mask
	var modalMask = jQuery('<div/>');
	modalMask.attr('id', 'modal-mask');
	modalMask.css('z-index', '50');
	jQuery('body').append(modalMask);

	// Select all the a tag with name equal to modal
	jQuery('[name=modal]').click(function(e)
	{
		// Cancel the link behavior
		e.preventDefault();
		
		// Get the href tag
		var id = jQuery(this).attr('href');
		
		// Fade in mask		
		jQuery('#modal-mask').fadeTo(200, 0.9);	
	
		// Get the window height and width
		var windowHeight = jQuery(window).height();
		var windowWidth = jQuery(window).width();
		
		// Get modal height and width
		var modalHeight = jQuery(id).getElementHeight();
		var modalWidth = jQuery(id).getElementWidth();
		
		// Create new modal and append the content
		var modalWindow = jQuery('<div />');
		modalWindow.css({'position' : 'fixed', 'float' : 'left', 'z-index' : '99', 'display' : 'none'});
		modalWindow.attr('id', 'modal-window');
		var modalInnerWindow = jQuery(id);
		modalInnerWindow.css('display', 'block');
		modalWindow.append(modalInnerWindow);
		modalWindow.addCorners('black');
		jQuery('body').append(modalWindow);
		
		// Create and append the close button
		var modalClose = jQuery('<div/>');
		modalClose.attr('id', 'modal-close');
		modalClose.html('<span class="close">Close</span>');
		modalWindow.append(modalClose);
		
		// If close button is clicked
		jQuery(modalClose).click(function (e)
		{
			jQuery(this).fadeOut(100);
			jQuery('#modal-window, #modal-mask').fadeOut(100);
			modalInnerWindow.css('display', 'none');
			jQuery('body').append(modalInnerWindow);
			jQuery('#modal-window').remove();
		});
		
		// If mask is clicked
		/*jQuery(modalMask).click(function ()
		{
			jQuery(modalClose).click();
		});*/
		
		// Set the modal window to center 
		modalWindow.css('top',  windowHeight/2-modalHeight/2);
		modalWindow.css('left', windowWidth/2-modalWidth/2);
	
		// Fade in window
		modalWindow.fadeIn(200);
	});
		
	/* Adds corner spans to selected element. */
	jQuery('.add-corners-white').each(function() { jQuery(this).addCorners(); });
	jQuery('.add-corners-black').each(function() { jQuery(this).addCorners('black'); });
	jQuery('.add-corners-custom').each(function() { jQuery(this).addCorners('custom'); });
	
	/* Tooltip */
	jQuery('.tooltip-handle').hover(function()
	{
		var tooltip = jQuery('<div class="tooltip"/>');
		tooltip.html(jQuery(this).attr('title'));
		jQuery(this).attr('title', '');
		tooltip.appendTo(jQuery(this));
		tooltip.css('top', -5  - tooltip.getElementHeight());
	}, function()
	{
		jQuery(this).attr('title', jQuery(this).find('.tooltip').html());
		jQuery(this).find('.tooltip').remove();
	});
	
	if (jQuery.cookie('videoloaded') == null)
	{
		/*jQuery('<div/>').addClass('modal-window').attr('id', 'introvideo').html('<div class="fine acenter">Welcome to Your Art Here, an all styles visual arts contest with a New York City theme</div><iframe id="vimeo2" src="http://player.vimeo.com/video/14633893?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff&amp;autoplay=1" width="600" height="338" frameborder="0"></iframe>').appendTo('body');*/
		jQuery('#introvideoa').click();
		jQuery.cookie('videoloaded', 'false');
	}
});

/* Adds corner spans to selected element. */
jQuery.fn.addCorners = function(type)
{
	if (type == 'black') theType = type;
	else if (type == 'custom')
	{
		theType = type;
		var customClass = jQuery(this).attr('custom');
		var hasCustomClass = false;
		if (customClass != '')
		{
			hasCustomClass = true;
			jQuery(this).addClass(customClass);
		}
	}
	else theType = 'white';
	var myElement = jQuery(this);
	var nw = jQuery('<span />');
	nw.addClass('corners-' + theType + ' nw');
	if (hasCustomClass) nw.addClass(customClass);
	myElement.append(nw);
	var ne = jQuery('<span />');
	ne.addClass('corners-' + theType + ' ne');
	if (hasCustomClass) ne.addClass(customClass);
	myElement.append(ne);
	var se = jQuery('<span />');
	se.addClass('corners-' + theType + ' se');
	if (hasCustomClass) se.addClass(customClass);
	myElement.append(se);
	var sw = jQuery('<span />');
	sw.addClass('corners-' + theType + ' sw');
	if (hasCustomClass) sw.addClass(customClass);
	myElement.append(sw);
}

/* Returns the correct height for the element, including padding and borders. */
jQuery.fn.getElementHeight = function()
{
	var elHeight = jQuery(this).height();
	var elPadding = parseFloat(jQuery(this).css('padding-top')) + parseFloat(jQuery(this).css('padding-bottom'));
	var elBorder = parseFloat(jQuery(this).css('border-top-width')) + parseFloat(jQuery(this).css('border-bottom-width'));
	elHeight += elPadding + elBorder;
	return elHeight;
}

/* Returns the correct width for the element, including padding and borders. */
jQuery.fn.getElementWidth = function()
{
	var elWidth = jQuery(this).width();
	var elPadding = parseFloat(jQuery(this).css('padding-left')) + parseFloat(jQuery(this).css('padding-right'));
	var elBorder = parseFloat(jQuery(this).css('border-left-width')) + parseFloat(jQuery(this).css('border-right-width'));
	elWidth += elPadding + elBorder;
	return elWidth;
}
	
/* Validation */
jQuery(document).ready(function()
{
	jQuery("#submit-entry").validate({
		rules: {
			artistfname: "required",
			agree: "required",
			artistlname: "required",
			artistemail: {
				required: true,
				email: true
			},
			artistcity: "required",
			artistabout: {
				required: true,
				maxlength: 450
			},
			artworkname: {
				required: true,
				maxlength: 50
			},
			artworktime: "required",
			artworkbudget: {
				required: true,
				minlength: 2
			},
			artworkabout: {
				required: true,
				maxlength: 450
			},
			artworkimage: "required"
		},
		messages: {
			artistfname: "Please enter your first name",
			agree: "You must agree to the terms and conditions",
			artistlname: "Please enter your last name",
			artistemail: "Please enter a valid e-mail",
			artistcity: "Please enter your city",
			artistabout: {
				required: "Please enter some text about you",
				maxlength: "The maximum of allowed characters is 450"
			},
			artworkname: {
				required: "Please enter a name for your artwork",
				maxlength: "Please enter a name for your"
			},
			artworktime: "Please estimate the time to produce the artwork",
			artworkbudget:  {
				required: "Please enter a budget for your artwork",
				minlength: "Please enter a budget for your artwork"
			},
			artworkabout: {
				required: "Please enter some text about your artwork",
				maxlength: "The maximum of allowed characters is 450"
			},
			artworkimage: "You must upload an image that represents your artwork"
		}
	});
});
/**
 * jQuery Maxlength plugin
 * @version		$Id: jquery.maxlength.js 18 2009-05-16 15:37:08Z emil@anon-design.se $
 * @package		jQuery maxlength 1.0.5
 * @copyright	Copyright (C) 2009 Emil Stjerneman / http://www.anon-design.se
 * @license		GNU/GPL, see LICENSE.txt
 */
 (function(A){A.fn.maxlength=function(B){var C=jQuery.extend({events:[],maxCharacters:10,status:true,statusClass:"status",statusText:"characters left",notificationClass:"notification",showAlert:false,alertText:"You have typed too many characters.",slider:false},B);A.merge(C.events,["keyup"]);return this.each(function(){var G=A(this);var J=A(this).val().length;function D(){var K=C.maxCharacters-J;if(K<0){K=0}G.next("div").html(K+" "+C.statusText)}function E(){var K=true;if(J>=C.maxCharacters){K=false;G.addClass(C.notificationClass);G.val(G.val().substr(0,C.maxCharacters));I()}else{if(G.hasClass(C.notificationClass)){G.removeClass(C.notificationClass)}}if(C.status){D()}}function I(){if(C.showAlert){alert(C.alertText)}}function F(){var K=false;if(G.is("textarea")){K=true}else{if(G.filter("input[type=text]")){K=true}else{if(G.filter("input[type=password]")){K=true}}}return K}if(!F()){return false}A.each(C.events,function(K,L){G.bind(L,function(M){J=G.val().length;E()})});if(C.status){G.after(A("<div/>").addClass(C.statusClass).html("-"));D()}if(!C.status){var H=G.next("div."+C.statusClass);if(H){H.remove()}}if(C.slider){G.next().hide();G.focus(function(){G.next().slideDown("fast")});G.blur(function(){G.next().slideUp("fast")})}})}})(jQuery);


/* Input Label Function
---------------------------*/
jQuery.fn.labelify = function(settings)
{
  settings = jQuery.extend({text: 'title', labelledClass: ''}, settings);
  var lookups = {
    title: function(input) {
      return jQuery(input).attr('title');
    },
    label: function(input) {
      return jQuery('label[for=' + input.id +']').text();
    }
  };
  var lookup;
  var jQuery_labellified_elements = jQuery(this);
  return jQuery(this).each(function() {
    if (typeof settings.text === 'string') {
      lookup = lookups[settings.text]; // what if not there?
    } else {
      lookup = settings.text; // what if not a fn?
    };
    // bail if lookup isn't a function or if it returns undefined
    if (typeof lookup !== 'function') { return; }
    var lookupval = lookup(this);
    if (!lookupval) { return; }

    // need to strip newlines because the browser strips them
    // if you set textbox.value to a string containing them    
    jQuery(this).data('label',lookup(this).replace(/\n/g,''));
    jQuery(this).focus(function() {
      if (this.value === jQuery(this).data('label')) {
        this.value = this.defaultValue;
        jQuery(this).removeClass(settings.labelledClass);
      }
    }).blur(function(){
      if (this.value === this.defaultValue) {
        this.value = jQuery(this).data('label');
        jQuery(this).addClass(settings.labelledClass);
      }
    });
    
    var removeValuesOnExit = function() {
      jQuery_labellified_elements.each(function(){
        if (this.value === jQuery(this).data('label')) {
          this.value = this.defaultValue;
          jQuery(this).removeClass(settings.labelledClass);
        }
      })
    };
    
    jQuery(this).parents('form').submit(removeValuesOnExit);
    jQuery(window).unload(removeValuesOnExit);
    
    if (this.value !== this.defaultValue) {
      // user already started typing; don't overwrite their work!
      return;
    }
    // actually set the value
    this.value = jQuery(this).data('label');
    jQuery(this).addClass(settings.labelledClass);
  });
};
