$(document).ready(function(){
	resize();
    $(window).resize( function(){
		resize();
    });	
	paging();
	viewMedal();
	$('*[rel], input.BrowseTextBoxStyle').each(function() {
        if ($(this).val() == '') {
            $(this).val($(this).attr('rel'));
        }
        $(this).attr('autocomplete', 'off');
    });
    
    $('*[rel]').each(function() {
        if ($(this).val() == '') {
            $(this).val($(this).attr('rel'));
        }
        $(this).attr('autocomplete', 'off');
    });
    $('*[rel]').bind('blur', function() {
        var rel = $(this).attr('rel');
        var text = $.trim($(this).val());
        if (text == '') {
            $(this).val(rel);
        }
    });
    $('*[rel]').bind('focus', function() {
        var rel = $(this).attr('rel');
        var text = $.trim($(this).val());
        if (text == rel) {
            $(this).val('');
        }
    });		
});

window.onload = function () {
	// Fix PNG for Ie 6
	if ( (/MSIE 6\.0/).test(navigator.userAgent) && !(/MSIE 7\.0/).test(navigator.userAgent) && !(/MSIE 8\.0/).test(navigator.userAgent) ) {	
		DD_belatedPNG.fix(".FixPng");
	}
}

function resize() {
	var hHeader = $("#header").height();
	var hFooter = $("#footer").height();
	var maxWidth = 1440;
	var minWidth = 1024;
	var window_w = jQuery.browser.safari ? window.innerWidth : jQuery(window).width();
    var window_h = jQuery.browser.safari ? window.innerHeight : jQuery(window).height();
	$('#main').css('height', window_h - (hHeader + hFooter + 35));
	if(	window_w < minWidth ) {
		$("#header").css('width', "100%");
		$("#footer").css({'width' : "100%", 'marginLeft' : 0, 'left': 0});
	}
	if(	window_w > minWidth  &&  window_w < maxWidth) {
		$("#header").css('width',  window_w);
		$("#footer").css({'width' : window_w, 'marginLeft' : 0, 'left': 0});
	}
	if(	window_w > maxWidth ) {
		$("#header").css('width', maxWidth);
		$("#footer").css({'width' : maxWidth, 'marginLeft' : -(maxWidth/2), 'left': '50%'});
	}	
}
function focusInput(jPar1, jPar2) {
	if(jPar2.val() == jPar1) {
		jPar2.val("");
	}
}
function blurInput(jPar1, jPar2) {
	if(jPar2.val() == '') {
		jPar2.val(jPar1);
	}
}
function isEmail (el) {
    var strEmail = el.val().replace(/(^ *)|( *$)/g, "");
    //if (!strEmail) return true;
    var reEmail = /^[&\'*+\/=?^_{}~a-z0-9.-]+@([a-z0-9-]+\.)+[a-z0-9]+$/;
    return reEmail.test(strEmail);
}
function paging() {
	var wPaging =0;
	$(".Paging a").each(function() {
		wPaging += $(this).outerWidth(true);
	});
	wPaging += ($(".Paging span.More").outerWidth(true) + $(".Paging span.Current").outerWidth(true));
	if ( (/MSIE 6\.0/).test(navigator.userAgent) ) {
		wPaging += 3;
	}	
	$(".Paging .Inner").css('width',  wPaging);
}
function closePopup(url, themeClass) {
    try {
	    if ($lightbox_active != null && $lightbox_active.hideLightBox) {
		    $lightbox_active.hideLightBox();
		}
		$lightbox_active = $lightbox.openPopup({
			href: url,
			closeBtnText: 'X',
	        themeClass: themeClass
		});

	}
	catch (err) {
	}
	return false;	
}
function viewMedal() {	
	var _item = $(".DetailContainer .Item");
	_item.find("img." + _item.find("a.Current").attr("rel")).show();
	_item.find(".Block > a").each(function(i) {			
		$(this).bind("click", function(){
			var current = _item.find("a.Current");
			current.removeClass("Current");	
			if ( (/MSIE 6\.0/).test(navigator.userAgent)) {
				DD_belatedPNG.applyVML(current.get(0));
			}	
			$(this).parent().parent().find("img").hide();
			$(this).parent().parent().find("img." + $(this).attr("rel")).show();
			$(this).addClass("Current");
			return false;
		})
	});
}