var isiPad = navigator.userAgent.match(/iPad/i) != null;
var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
var isiPod = navigator.userAgent.match(/iPod/i) != null;
var msie6 = jQuery.browser == 'msie' && jQuery.browser.version < 7;

//$.noConflict();
jQuery(document).ready(function($) {
	
	// Checkbox selection with highlight of recap_box
    
	if($('.item_list').length > 0){
		$(".item_list :checkbox").click(function(){
			if($(this).is(':checked'))
				$(this).parents('li').addClass('selected');
			else
				$(this).parents('li').removeClass('selected');
			
			if($('.recap_box').length > 0)
				$(".recap_box").fadeOut(250).fadeIn(250);
		});
	}


	// Popup that doesn't move with window scroll

	if($('.popup').length > 0){
		$(".popup").overlay({
			// some mask tweaks suitable for modal dialogs
			mask: {
				color: '#000',
				loadSpeed: 200,
				opacity: 0.5
			},
			closeOnClick: false
		});
	}

	
	// Popup that move with window scroll
	if($('.popup_nofixed').length > 0){
		$(".popup_nofixed").overlay({
			// some mask tweaks suitable for modal dialogs
			mask: {
				color: '#000',
				loadSpeed: 200,
				opacity: 0.5
			},
			fixed: false,
			closeOnClick: false
		});
	}
	
	// Edit in place
	if($('.edit_in_place').length > 0){
		$('.edit_in_place div a').click(function(){
			$(this).parents('.edit_in_place div').fadeOut(300,function(){
				var form = $(this).next();
				form.children('input[type=text]').val($(this).children('.edit_in_place_original').text());
				form.fadeIn(300);
			});
			return false;
		});
		$('.edit_in_place_reset').click(function(){
			var form = $(this).parents('form');
			form.fadeOut(300,function(){
				$(this).prev().fadeIn(300);
			});
			return false;
		});
	}

	// Floating Box

	if($('#float_box').length > 0 && !msie6 && !isiPad && !isiPhone && !isiPod) {		
		var top = $('#float_box').offset().top-95;
		$(window).scroll(function (event) {
			if ($(this).scrollTop() >= top) {
				$('#float_box').addClass('fixed');
			} else {
				$('#float_box').removeClass('fixed');
			}
		});
	}
	/*
	$('.paginator_next').click(function(){
		$('ul.item_list').slSpinner();
		setTimeout(function(){$('ul.item_list').slSpinner('destroy');},4000);
		return false;
	});
	
	$('.paginator_prev').click(function(){
		$('ul.item_list').slSpinner();
		setTimeout(function(){$('ul.item_list').slSpinner('destroy');},4000);
		return false;
	});
	*/	
	
	// Mediaclip
	if($('#mediaclip_container').length > 0){
		$('#mediaclip_container').height($(window).height()-60);
  	  	//$('html, body').animate({scrollTop:$('.white_box').offset().top-5}, 'slow');
//*lux*/  	  	$('html, body').animate({scrollTop:$('#mediaclip_container').offset().top+20}, 'slow');
  	}
});

(function( $ ){

	var settings = {
		'className'     : 'spinner',
		'fade'			: true			
	};

	var methods = {
  
		init : function( options ) {
     	
   			return this.each(function() {        
			
				if ( options ) 
					$.extend( settings, options );
				
				if($(this).next().hasClass('spinner'))
					return false;
				
				var container = $('<div />').css('position','relative');
				$(this).wrap(container);
				
				var spinner = $('<div />', {
		           'class' : settings.className
		        });
		
				// add properties
				spinner.css({
					'width': 	$(this).width(),
					'height':	$(this).height(),
					'left':		0,
					'top':		0,
					'padding':	0,
					'margin':	0,
					'position':	'absolute'
				});
				
				$(this).after(spinner);
				
				if(settings.fade)
					spinner.hide().fadeIn();
			
			})
     	},
		destroy : function( ) {
		
			return this.each(function(){
			
				if($(this).next().hasClass(settings.className)){
					$(this).next().fadeOut('slow',function(){
						$(this).unwrap();
						$(this).remove();
					});
				}
					
			})
		}
	};

	$.fn.slSpinner = function( method ) {
    
		if ( methods[method] ) {
			return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.slSpinner' );
		}    
  
	};

})( jQuery );



