$(document).ready(function() {

	/* Accessible input values
	---------------- */
	$("input.propagate").each(function(){
	var $this = $(this);
	var val = $('label[for=' + $this.attr('id') + ']').html();
	if($this.val() == '') $this.val(val);
	$this.focus(function(){
			if($this.val() == val) $this.val('');
	}).blur(function(){
			if($this.val() == '') $this.val(val);
	});
	});
	

	/**
	* gallery rollover	
	 */
	 
	if ($('.gallery-viewport').length > 0){

		$('.gallery-viewport > ul > li').hover(function(e){
			$(this).addClass('hover');
			var mX = e.clientX,
			mY = e.clientY;

		$(this).children('div.rollover').css({ 
			left: $(document).scrollLeft() + e.clientX - $(this).offset().left, 
			top: $(document).scrollTop() + e.clientY - $(this).offset().top 
		});
	
		$(this).children('div.rollover-flip').css({ 
			left: $(document).scrollLeft() + e.clientX - $(this).offset().left, 
			top: $(document).scrollTop() + e.clientY - $(this).offset().top 
		});
		
		$(this).children('div.rollover-t').css({ 
			left: $(document).scrollLeft() + e.clientX - $(this).offset().left, 
			top: $(document).scrollTop() + e.clientY - $(this).offset().top 
		});
		
		$(this).children('div.rollover-flip-t').css({ 
			left: $(document).scrollLeft() + e.clientX - $(this).offset().left, 
			top: $(document).scrollTop() + e.clientY - $(this).offset().top 
		});
	
		var divY = parseInt($(this).children('div.rollover').css('top')),
		divX = parseInt($(this).children('div.rollover').css('left'));
	
		var divY2 = parseInt($(this).children('div.rollover-flip').css('top')),
		divX2 = parseInt($(this).children('div.rollover-flip').css('left')) - 265;
		
		var divY3 = parseInt($(this).children('div.rollover-t').css('top')) - 206,
		divX3 = parseInt($(this).children('div.rollover-t').css('left'));
		
		var divY4 = parseInt($(this).children('div.rollover-flip-t').css('top')) - 206,
		divX4 = parseInt($(this).children('div.rollover-flip-t').css('left')) - 256;

		$(this).mousemove(function(e){
			$(this).children('div.rollover').css({ top: divY + (e.clientY - mY), left: divX + (e.clientX - mX) });
			$(this).children('div.rollover-flip').css({ top: divY2 + (e.clientY - mY), left: divX2 + (e.clientX - mX) });
			$(this).children('div.rollover-t').css({ top: divY3 + (e.clientY - mY), left: divX3 + (e.clientX - mX) });
			$(this).children('div.rollover-flip-t').css({ top: divY4 + (e.clientY - mY), left: divX4 + (e.clientX - mX) });
		});
	


			}, function(){
			$(this).removeClass('hover');
			$(this).unbind('mousemove');
		});
	}

	/**
	* popup login
	*/
	if ($('.overlay').length > 0){
		$('.overlay').css('height', $(document).height());
		$('.vote').click(function(){
			$('.overlay').fadeIn();
		});
		$('.overlay .popup-layer .close-popup').click(function(){
			$('.overlay').fadeOut();
		})
	}


	/**
	* custom forms
	*/
	$('input.styled, span.styled input').each(function() {
		var el = $(this);
		el.hide();
		type = el.attr('type');
		klass = 'custom-' + type;
		if (el.attr('checked') == true) { klass = klass + ' custom-' + type + '-checked'; }
		el.before('<span class="' + klass + '">&nbsp;</span>' );
		el.data('custom', el.prev());
		if (type == 'radio') {
			el.data('label', el.parent('label'));
			el.data('label').click(function(e) {
				e.preventDefault();
				input = $(this).find('input');
				$('input[name="' + input.attr('name') + '"]').each(function() {
					$(this).data('custom').removeClass('custom-radio-checked');
				});
				input.attr('checked', true);
				input.data('custom').addClass('custom-radio-checked');
			}); 
		} else {
			function toggleCheckbox(el, custom) {
				if (el.attr('checked')) {
					el.attr('checked', false);
					custom.removeClass('custom-checkbox-checked')
				} else {
					el.attr('checked', true);
					custom.addClass('custom-checkbox-checked');
				}				
			}

			el.data('label', $('label[for="' + el[0].id + '"]'));
			el.data('label').click(function(e) {
				e.preventDefault();
				toggleCheckbox(el, el.data('custom'))
			});
			el.data('custom').click(function(e) {
				e.preventDefault();
				toggleCheckbox(el, $(this))
			});
		}
	});
	
	
	$('.uploadImage').change(function() {
		uploadvalue = $('.uploadImage').val();						   
		$('#fileUploadStyle').val(uploadvalue);
	  });
	
	
});

