(function($) {
  var userAgent = navigator.userAgent.toLowerCase();
  var ie_version = -1;
  if (navigator.appName == 'Microsoft Internet Explorer') {
   var re = new RegExp("msie ([0-9]{1,}[\.0-9]{0,})");
   if (re.exec(userAgent) != null)
   ie_version = parseFloat(RegExp.$1);
  }
  $.browser = {
    version: (ie_version>-1)?ie_version:(userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
    safari: /webkit/.test( userAgent ),
    opera: /opera/.test( userAgent ),
    msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
    mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
  };
})(jQuery);


jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
};
//$.preloadImages("images/modal_bottom_bg.png", "images/modal_top_bg.png");

function show_sub_menu(obj){
	if($(obj).parent().find('ul').css('display') == "none"){
		$(obj).parent().find('ul').css({display: "none"});
		$(obj).find('ul').css({display: "block"});
	} else {
		$(obj).parent().find('ul').css({display: "none"});
	}
	return false;
}
function hide_sub_menu(obj){
	$(obj).parent().find('ul').css({display: "none"});
}

$(function () {
    var tabContainers = $('div#bottom_tabs > div');
    tabContainers.hide().filter(':first').show();

    $('div#bottom_tabs ul li a').click(function () {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('div#bottom_tabs ul li a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();
});

$(function () {
    var tabContainers = $('div#item_tabs > div');
    tabContainers.hide().filter(':first').show();

    $('div#item_tabs ul li a').click(function () {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('div#item_tabs ul li a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();
});



function  getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return [pageWidth,pageHeight,windowWidth,windowHeight];
}

function getBodyScrollTop(){
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function show_modal(){
var tmp = Array();
tmp = getPageSize();

	if(tmp['3'] > 757){
		if($.browser.version == 6){
			$('#all_modal').addClass('ie6_fixed');
			$('select').css({visibility: "hidden"});
		}else{
		document.getElementById('all_modal').style.position = 'fixed';
		document.getElementById('all_modal').style.top = ((tmp['3']-757)/2)+'px';		
		}
	}else{
		if($.browser.version == 6){
			$('select').css({visibility: "hidden"});
			document.getElementById('all_modal').style.top = (getBodyScrollTop())+'px';
		}else{
			document.getElementById('all_modal').style.top = (getBodyScrollTop())+'px';
		}	
	}
	document.getElementById('all_modal').style.display = 'block';
	show_shadow();
}
function hide_modal(){
	$('select').css({visibility: "visible"});
	document.getElementById('all_modal').style.display = 'none';
	hide_shadow();
}

function show_modal2(id,name,detail_url){

$('#all_modal2').attr('element_id',id);
$('#all_modal2').attr('element_name',name);
$('#all_modal2').attr('detail_url',detail_url);

$('#element_name').attr('href', detail_url);
$('#element_name').html(name);

var tmp = Array();
tmp = getPageSize();

	if(tmp['3'] > 720){
		if($.browser.version == 6){
			$('#all_modal2').addClass('ie6_fixed');
			$('select').css({visibility: "hidden"});
		}else{
		document.getElementById('all_modal2').style.position = 'fixed';
		document.getElementById('all_modal2').style.top = ((tmp['3']-720)/2)+'px';		
		}
	}else{
		if($.browser.version == 6){
			$('select').css({visibility: "hidden"});
			document.getElementById('all_modal2').style.top = (getBodyScrollTop())+'px';
		}else{
			document.getElementById('all_modal2').style.top = (getBodyScrollTop())+'px';
		}
	}
	document.getElementById('all_modal2').style.display = 'block';
	show_shadow2();
}
function hide_modal2(){
	$('select').css({visibility: "visible"});
	document.getElementById('all_modal2').style.display = 'none';
	hide_shadow2();
}


/*shadow*/

function getPageScroll(){
    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array('',yScroll) 
    return arrayPageScroll;
}
function getPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {  
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }   
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){  
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

function show_shadow(){
    var objOverlay = document.getElementById('overlay');
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

    objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';
}

function hide_shadow(){
    objOverlay = document.getElementById('overlay');
    objOverlay.style.display = 'none';
}

function show_shadow2(){
    var objOverlay = document.getElementById('overlay2');
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

    objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';
}

function hide_shadow2(){
    objOverlay = document.getElementById('overlay2');
    objOverlay.style.display = 'none';
}
