$(document).ready(function(){
    $('#boxes li').mouseenter(function(){
        $('#boxes li').css('position', 'relative');
		
		$(this).animate({
                    top: '-10px'
                }, 400);
		
		/*
        $('#boxes li').each(function(index){
            var current_x = $(this).scrollLeft();
            var rand_mark = Math.floor(Math.random() * 31);
            var new_dim = current_x + rand_mark;
            if (rand_mark > 10) {
                var new_top = 0;
                $(this).animate({
                    top: new_top + 'px',
                    right: new_dim + 'px'
                }, 400);
            }
            else {
                var new_top = new_dim - 20;
                $(this).animate({
                    top: new_top + 'px',
                    left: new_dim + 'px'
                }, 200);
            }
        });
        */
    })
	
	$('#boxes li').mouseleave(function(){
		$('#boxes li').css('position', 'relative');
		$(this).animate({
                    top: '0'
                }, 400);
	})
	
	$('#hp_boxes li').mouseleave(function(){
		$('#hp_boxes li').css('position', 'relative');
		$(this).animate({
                    top: '0'
                }, 400);
	})
    
    $('#hp_boxes li').mouseenter(function(){
    
        $('#hp_boxes li').css('position', 'relative');
        
		$(this).animate({
                    top: '-10px'
                }, 400);	
        /*
		$('#hp_boxes li').each(function(index){
            var current_x = $(this).scrollLeft();
            
            var rand_mark = Math.floor(Math.random() * 31);
            //alert(current_x+rand_mark);
            //var new_dim = current_x + rand_mark;
            var new_dim = current_x;
            
            if (rand_mark > 10) {
            
                var new_top = new_dim + 10;
                $(this).animate({
                    top: new_top + 'px',
                    right: new_dim + 'px'
                }, 400);
                
            }
            else {
                var new_top = new_dim - 10;
                $(this).animate({
                    top: new_top + 'px',
                    left: new_dim + 'px'
                }, 200);
            }
            
        });
        */
    })
    
    
    $('.zoom').colorbox({
        current: "{current} / {total}"
    });
    
    $('ul#hp_boxes li a').hover(function(){
        $(this).children('span.text').fadeIn(200);
    }, function(){
        $(this).children('span.text').fadeOut(200);
    });
    
    $('#boxes a span').hover(function(){
        $(this).css('background-position', 'left bottom')
    }, function(){
    
        if (!$(this).hasClass('current')) {
            $(this).css('background-position', 'left top')
        }
        
        
    })
    
    $('#c_form label.infield').each(function(){
        var label_value = $(this).text();
        var label_target = $('#' + $(this).attr('for'));
        
        if ('' === label_target.val()) {
            label_target.val(label_value);
        }
        label_target.attr('title', label_value);
        $(this).hide();
        
        label_target.focus(function(){
            if (label_target.val() === label_target.attr('title')) {
                label_target.setCursorPosition(0);
                
                label_target.css('color', '#DDDDDD');
                //label_target.val('');
            }
        });
        
        label_target.keypress(function(){
            label_target.css('color', 'black');
            if (label_target.val() === label_target.attr('title')) {
                label_target.val('');
            }
        });
        
        
        label_target.blur(function(){
            label_target.css('color', '#838383');
            if (label_target.val() === '') {
            
                label_target.val(label_target.attr('title'));
            }
        });
        
    })
    
    $.fn.setCursorPosition = function(pos){
        this.each(function(index, elem){
            if (elem.setSelectionRange) {
                elem.setSelectionRange(pos, pos);
            }
            else 
                if (elem.createTextRange) {
                    var range = elem.createTextRange();
                    range.collapse(true);
                    range.moveEnd('character', pos);
                    range.moveStart('character', pos);
                    range.select();
                }
        });
        return this;
    };
    
});


function swip(elementInput, swipFrom, swipTo){
    if (elementInput.value == swipFrom) 
        elementInput.value = swipTo;
}

