

$(document).ready(function(){

    //window resize
    $(window).resize(backgroundResize);

    //click on/off gfa content
    actionOnOffGFAContent();
    
    //click men tab
    actionTabMenu();
            
});


function backgroundResize() {
  //check image
  if($('.bgImage img').length > 0) {
        $('.bgImage img').each(function(){
            var oImg = new Image();
            oImg.src = $(this).attr('src');
            var imgOrg = $(this);
            
            //incase browser is not ie
            if(oImg.width==0)
                oImg.width = parseInt(imgOrg.attr('width'));
            if(oImg.height==0)
                oImg.height = parseInt(imgOrg.attr('height'));
           
            $(oImg).ready(function() {
              var orgW = oImg.width;
              var orgH = oImg.height;
              if(orgW != 0 && orgH != 0) {
      	        var h = $(window).height();
      	        var w = $(window).width();
      	        var ratioW = w / orgW;
      	        var ratioH = h / orgH;
      	        if(ratioW > ratioH) {
      		        imgOrg.css({'height':(w * orgH / orgW), 'width':w});
      	        } else {
      		        imgOrg.css({'height':h, 'width':(h * orgW / orgH)});
      	        }
    	      }
  	        });
        })
    }
}

function actionOnOffGFAContent(){
    //set GFAContent  on / off
    $("#GFAContent img").click(function(){
        $("#GFAContent").slideToggle('normal',function(){
            $("#btnGFA").slideToggle('fast');
        });
        return false;
    });
    
    $("#btnGFA a").click(function(){
        $("#btnGFA").slideToggle('normal',function(){
            $("#GFAContent").slideToggle('normal');
        });
        return false;
    });
}

function actionTabMenu(){
    //set tab Menu
    $("#tag > ul > li a").click(function(){
       //reset tab 
       $("#tag > div:visible").hide();
       $("#tag > ul > li > a.highlight").removeClass('highlight');
       
       //set tab selected
       $(this).addClass('highlight');
       
       //show content selected
       switch($(this).parent('li').attr('class')){
        case 'gfa' : $("#tagSt").show(); break;
        case 'franchise' : $("#tagNd").show(); break;
        case 'news' : $("#tagRd").show(); break;
       }
       
       return false;
    });
}


