/*
 * @version 2.0.0
 * @create  2011-08-30
 * @update  2011-09-21
 */


/**	lightwindow 
--------------------------------------------------------------**/
jQuery(function() {
	jQuery('a.lightwindow').click(function(){
		return false;
	});
});

function windowFlesh () {
   //window.reload(true);
   window.location.reload(true);
}


/**	Side Navi 
--------------------------------------------------------------**/
var ssTimer = null;
var ssSetTimer = function(){
	ssTimer = setTimeout("setSideNav()", 500);
}

jQuery(document).ready(function() {
	jQuery('#sideNav').css({
		opacity : 0.7
	});
	setSideNav();
});

jQuery(window).bind('resize', function() {
	clearTimeout(ssTimer);
	ssSetTimer();
});

jQuery(window).scroll(function(){
	clearTimeout(ssTimer);
	ssSetTimer();
});

function setSideNav() {

	var ssTop = jQuery(window).scrollTop();
	
	if(ssTop != 0){
		jQuery('#sideNav').animate({
			top : ssTop+200
		});
	}else{
		jQuery('#sideNav').animate({
			top : 200
		});
	}
	
	clearTimeout(ssTimer);
}

jQuery(function(){

	jQuery('#sideNav').mouseover(function() {
		jQuery(this).css({
			opacity : 1
		});
	}).mouseout(function() {
		jQuery(this).css({
			opacity : 0.7
		});
	});

});



/**	Login Box 
--------------------------------------------------------------**/
jQuery(function(){
				
	var htl = jQuery('#headuserInfo');
	var hts = jQuery('#headuserRegistShort');
	
	htl.hide();
	hts.show();

	jQuery(window).bind('load', function() {
		
		var logvarID = jQuery.cookie('logvar');

		if(logvarID == null || logvarID == 0) {
			jQuery.cookie('logvar', 0, { expires: 7 , path :'/' });
			logvarID = jQuery.cookie('logvar');
			
			hts.slideToggle('slow',
					function(){
						htl.toggle('slow');
					});
		}
		//else {
		//	htl.hide();
		//	hts.show();
		//}
	
		jQuery('.hnavToggle').click(function () {
	
			logvarID = jQuery.cookie('logvar');
											  
			if(logvarID == null || logvarID == 0) {
				
				jQuery.cookie('logvar', 1, { expires: 7 , path :'/' });
				htl.toggle('slow',
					function(){
						hts.slideToggle('slow');
					});
				
			} else {
				
				jQuery.cookie('logvar', 0, { expires: 7 , path :'/' });
				hts.slideToggle('slow',
					function(){
						htl.toggle('slow');
					});
				
			}
			
		});	
	});	

});


jQuery(function(){

	/**	Tooltip **/
	jQuery('a[rev=tooltip]').mouseover(function(e) {
												
		var tooltip = jQuery('#tooltip');	
		var tip = jQuery(this).attr('title');	
		
		jQuery(this).attr('title','');
		jQuery('#wrap').append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');	
				
		jQuery('#tooltip').fadeIn('500');
		jQuery('#tooltip').fadeTo('10',0.9);
		jQuery('#tooltip').css('top', e.pageY + 10 );
		jQuery('#tooltip').css('left', e.pageX + 20 );

		
	}).mousemove(function(e) {
	
		jQuery('#tooltip').css('top', e.pageY + 10 );
		jQuery('#tooltip').css('left', e.pageX + 20 );
		
	}).mouseout(function() {
	
		jQuery(this).attr('title',jQuery('.tipBody').html());
		jQuery('#wrap').children('div#tooltip').remove();
		
	});

	
	/**	Language **/
	jQuery('#hnavLanguage').click(function(){

		jQuery('#headnav dd:not(:animated)')
				.css({
					'display' : 'block',
					'opacity' : 0
				})
				.animate({	opacity: 1	},200
				);
	});

	jQuery('#hnavLangBtn').hover(function(){
			
	},function(){

		jQuery('#headnav dd')
				.animate({opacity: 0},200,
					function(){
						jQuery(this).css('display','none');
					}
				);
	});
	

	/**	forminput **/
	jQuery('input[title]').each(function() {  
        if(jQuery(this).val() === '') {  
            jQuery(this).val(jQuery(this).attr('title'));   
        }  
          
        jQuery(this).focus(function() {  
            if(jQuery(this).val() == jQuery(this).attr('title')) {  
                jQuery(this).val('').addClass('focused');      
            }  
        });  
        jQuery(this).blur(function() {  
            if(jQuery(this).val() === '') {  
                jQuery(this).val(jQuery(this).attr('title')).removeClass('focused');    
            }  
        });  
    });
	
	jQuery('.hulpass-clear').show();
	jQuery('.hulpass-password').hide();

	jQuery('.hulpass-clear').focus(function() {
    	jQuery('.hulpass-clear').hide();
    	jQuery('.hulpass-password').show();
    	jQuery('.hulpass-password').focus();
	});
	jQuery('.hulpass-password').blur(function() {
    	if(jQuery('.hulpass-password').val() == '') {
        	jQuery('.hulpass-clear').show();
			jQuery('.hulpass-password').hide();
		}
	});

});


/**
 * Flatten height same as the highest element for each row.
 *
 * Copyright (c) 2011 Hayato Takenaka
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * @author: Hayato Takenaka (http://urin.take-uma.net)
 * @version: 0.0.2
**/
;(function($) {
	jQuery.fn.tile = function(columns) {
		var tiles, max, c, h, last = this.length - 1, s;
		if(!columns) columns = this.length;
		this.each(function() {
			s = this.style;
			if(s.removeProperty) s.removeProperty("height");
			if(s.removeAttribute) s.removeAttribute("height");
		});
		return this.each(function(i) {
			c = i % columns;
			if(c == 0) tiles = [];
			tiles[c] = jQuery(this);
			h = tiles[c].height();
			if(c == 0 || h > max) max = h;
			if(i == last || c == columns - 1)
				jQuery.each(tiles, function() { this.height(max); });
		});
	};
})(jQuery);

/*
 * jQuery.rollover
 *
 * @version    1.0.4
 * @author     Hiroshi Hoaki <rewish.org@gmail.com>
 * @copyright  2010-2011 Hiroshi Hoaki
 * @license    http://rewish.org/license/mit The MIT License
 * @link       http://rewish.org/javascript/jquery_rollover_plugin
 *
 * Usage:
 * jQuery(document).ready(function($) {
 *   // <img>
 *   jQuery('#nav a img').rollover();
 *
 *   // <input type="image">
 *   jQuery('form input:image').rollover();
 *
 *   // set suffix
 *   jQuery('#nav a img').rollover('_over');
 * });
 */

jQuery.fn.rollover = function(suffix) {
	suffix = suffix || '_on';
	var check = new RegExp(suffix + '\\.\\w+$');
	return this.each(function() {
		var img = jQuery(this);
		var src = img.attr('src');
		if (check.test(src)) return;
		var _on = src.replace(/\.\w+$/, suffix + '$&');
		jQuery('<img>').attr('src', _on);
		img.hover(
			function() { img.attr('src', _on); },
			function() { img.attr('src', src); }
		);
	});
};

jQuery(function(){
	jQuery('.over').rollover('_ov');
	jQuery('form input:image').rollover('_ov')
});


/*
 * jQuery.Scroll
 */

jQuery().ready(function(){
	jQuery('.scroll').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target	|| jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({scrollTop: targetOffset}, 800);
				return false;
			}
		}
	});
});
