jQuery.noConflict();

jQuery.event.add(window, "load", setBackgroundImage);
jQuery.event.add(window, "resize", setBackgroundImage);

jQuery(document).ready(function($){
	
  jQuery('body').browserDetection();
  
  $('div.meta_nav > ul > li.unternavi').hover(
		function() { $('ul', this).css('display', 'block'); $(this).addClass('active');},
		function() { $('ul', this).css('display', 'none'); $(this).removeClass('active');  
  });
  
    $('div.meta_nav > ul > li.nounternavi').hover(
		function() { $(this).addClass('active');},
		function() { $(this).removeClass('active');  
  });

  
  if($('.bg_switch img.bg_image_th').length > 0){
	  $('.bg_switch img.bg_image_th').click(function(e){
		var newImage = $(this).attr('title');
		if(newImage.length > 0)
			
		  jQuery.ajax({
		    url: '/global/wGlobal/scripts/functions.php?backgroundImage='+newImage,
		    type: 'GET',
		    timeout: 100,
		    dataType: 'html'
		  }); 			
			
		  $('#bg_image_container #bg_image').attr('src', newImage);
	  });
  }
  if($('.list_images a.image').length > 0){
	$('.list_images a.image').click(function(e){
	  e.preventDefault();
	  var idImage = $(this).attr('id').replace('view_', '');
	  $(this).siblings().removeClass('active');
	  $(this).addClass('active');
	  

	 
	/*$('.single_image img').fadeOut(800,function() { $('.single_image img').attr('src','/global/wGlobal/layout/images/trans.gif').attr('src',Images[parseInt(idImage)]); });
	
	while($('.single_image img').height() != 403){
		
	}

	setTimeout(function() { $('.single_image img').fadeIn(800); }, 1000);*/


$(".single_image img").animate({opacity: 0.0}, 800,function()
	{	
	$('.single_image img').attr("src", Images[parseInt(idImage)])
	 .load(function()
		{
		$('.single_image img').animate({opacity: 1.0}, 800);                      
		}); 
	});	
  
  
/*	$('.single_image img').fadeOut(800);
	$('.single_image img').attr('title', Title[parseInt(idImage)]);
	$('.single_image img').attr('alt', Title[parseInt(idImage)]);
	$('.single_image img').attr('src',Images[parseInt(idImage)]);
	$('.single_image img').fadeIn(800);*/
	
	});
  }
});

function setBackgroundImage(){
  var height = jQuery(window).height();
  var width  = jQuery(window).width();
   
  //jQuery('#bg_image_container').css('width',width+'px');	  
  //jQuery('#bg_image_container').css('height',height+'px'); 
  
  jQuery("#bg_image").css('height',((width/height) >= (1280/1024)) ? 'auto' : '100%');
  jQuery("#bg_image").css('width',((width/height) >= (1280/1024)) ? '100%' : 'auto');
}

jQuery.fn.browserDetection = function() {
	jQuery.os = {name: (/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris')};
	
	var userAgent = navigator.userAgent.toLowerCase();
	
	jQuery.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
	
	if(jQuery.browser.msie){
	    jQuery('body').addClass('browserIE');
	    jQuery('body').addClass('browserIE' + jQuery.browser.version.substring(0,1));
	}
	
	if(jQuery.browser.chrome){
	
	    jQuery('body').addClass('browserChrome');
	    userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
	    userAgent = userAgent.substring(0,1);
	    jQuery('body').addClass('browserChrome' + userAgent);
	    
	    jQuery.browser.safari = false;
	}
	
	if(jQuery.browser.safari){
	    jQuery('body').addClass('browserSafari');
	    userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
	    userAgent = userAgent.substring(0,1);
	    jQuery('body').addClass('browserSafari' + userAgent);
	}
	
	
	if(jQuery.browser.mozilla){
	    if(navigator.userAgent.toLowerCase().indexOf('firefox') != -1){
	        jQuery('body').addClass('browserFirefox');
	        userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);
	        userAgent = userAgent.substring(0,1);
	        jQuery('body').addClass('browserFirefox' + userAgent);
	    }
	    else{
	        jQuery('body').addClass('browserMozilla');
	    }
	}
	
	if(jQuery.browser.opera){
	    jQuery('body').addClass('browserOpera');
	}
	
	jQuery('body').addClass(jQuery.os.name);
};
