function f_show_totop()
{
	var $show_to_top_area = 50;
	var $doc_height = $(document).height();
	var $win_height = $(window).height();
	var $scroll = pageYOffset;
	var $offset = $doc_height - $win_height - $show_to_top_area
	
	if ($offset < $scroll)
	
	{
		$('#to_top').fadeIn('fast');	
	}
 
 	else
 	{
 		$('#to_top').fadeOut('fast');		
 	}
}

function f_fixed_background()
{
	if ($(window).width() < 1024)
		{
			$('#bg').css({'position':'fixed','margin-left':'0px','left':'0px'});
		}
		else
		{
			$('#bg').css({'height':'100%', 'left':'50%', 'margin-left':'-522px', 'position':'fixed'});
		}
}

/* change position of div.bg */
$(window).resize(function()
{	
	var deviceAgent = navigator.userAgent.toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
    
	if (agentID) 
	{

	}
	else
	{
		f_fixed_background();	
	}	
});
$(document).ready(function()
{	
	var deviceAgent = navigator.userAgent.toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
    
	if (agentID) 
	{

	}
	else
	{
		f_fixed_background();	
	}
});

/* hide links on img */
$(document).ready(function(){
	$("a[rel^='attachment']").prop("href", "javascript:void(0);");
	$(".wp-caption").find('a').prop("href", "javascript:void(0);");
	$(".wp-caption").find('a').css("cursor", "default");
});


/* show and hide "back to top" button */
$(document).ready(function()
	{
		$('#to_top').hide();
});

$(document).scroll(function(){
	
	var deviceAgent = navigator.userAgent.toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
    
	if (agentID)
	{
	
	}
	else
	{
		f_show_totop();
	}
});

// jQuery SmoothScroll | Version 11-06-11
$(document).ready(function() {

   $('a[href*=#]').click(function() {

      // skip SmoothScroll on links inside sliders or scroll boxes also using anchors or if there is a javascript call
      if($(this).parent().attr('class')=='scrollable_navigation' || $(this).attr('href').indexOf('javascript')>-1) return;

      // duration in ms
      var duration=200;

      // easing values: swing | linear
      var easing='swing';

      // get / set parameters
      var newHash=this.hash;
      var oldLocation=window.location.href.replace(window.location.hash, '');
      var newLocation=this;

      // make sure it's the same location      
      if(oldLocation+newHash==newLocation)
      {
         // get target
         var target=$(this.hash+', a[name='+this.hash.slice(1)+']').offset().top;

         // adjust target for anchors near the bottom of the page
         if(target > $(document).height()-$(window).height()) target=$(document).height()-$(window).height();         

         // set selector
         if($.browser.safari) var animationSelector='body:not(:animated)';
         else var animationSelector='html:not(:animated)';

         // animate to target and set the hash to the window.location after the animation
         $(animationSelector).animate({ scrollTop: target }, duration, easing, function() {

            // add new hash to the browser location
            window.location.href=newLocation;
         });

         // cancel default click action
         return false;
      }
   });

	$("p:has(img)").css('margin' , '0');

});

