var felements = new Array();
var flcount = 1;
var preloadnavimg = new Array();
  
  
function loadFlashElements(){
  for (x in felements) {
    swfobject.embedSWF(felements[x][0], felements[x][1], felements[x][2], felements[x][3], "9.0.115", false, felements[x][4], felements[x][5], felements[x][6]);
  }
}



function ajaxFrame(elements){
  if(!elements){
    elements = '.aframe';
  }
  $(elements).each(afLoad);  
}

function afLoad(index){
  if($(this).attr('src')!='undefined' && $(this).attr('src')!= null){
    leftmargin = $(this).width()/2;
    $(this).prepend("<div style='display:block;width:110px;height:23px;background:silver;opacity:0.4;filter:alpha(opacity=40);position:absolute;z-index:40;margin-left:"+leftmargin+"px;left:-55px;'><div style='padding:5px;color:black;width:100px;height:13px;font-size:11px;text-align:center;font-weight:bold;'>LOADING</div></div>");
    if($(this).attr('cache') != 'false' && $(this).attr('cache') == 'no' && $(this).attr('cache') != '0'){
    uni=0;
    }else{
    uni = Math.floor(Math.random()*121);
    }
    if($(this).attr('id') == ''){
      $(this).attr('id','frameid'+index);
    }
    $.get($(this).attr('src'),{'uni':uni,'frameid':$(this).attr('id')},afLoaded);
  }
}

function afLoaded(data, textStatus) {
  var queryString = this.url.replace(/^[^\?]+\??/,'');			
	var params = afParseQuery(queryString);
  $('#'+params.frameid).text('');
  $('#'+params.frameid).append(data);
  fixVideoLinks();
  setSignupLinks();
  titliseImageLinks();
  $("#"+params.frameid + " a").filter(function(){return $(this).attr('target') == null || $(this).attr('target') == '' || $(this).attr('target') == 'undefined' || $(this).attr('target') == '_self'}).attr('afparent',params.frameid).click(function(event){
    event.preventDefault();
    targetFrame = $(this).attr('afparent');
    clickSRC = $(this).attr('href');
    $('#'+targetFrame).attr('src',clickSRC);
    ajaxFrame('#'+targetFrame);
  });
  $("#"+params.frameid + " a[target='_parent']").click(function(){
    event.preventDefault();
    document.location.href=$(this).attr('href');    
  });
  $("#"+params.frameid + " a[target^='af%']").click(function(event){
    event.preventDefault();
    targetFrame = $(this).attr('target').substr(3)+'.aframe';
    clickSRC = $(this).attr('href');
    $('#'+targetFrame).attr('src',clickSRC);
    ajaxFrame('#'+targetFrame);  
  });
}
    
function afParseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}


function addGradients(elements){
  $(elements).gradient({
    from:'F9EFEC',
    to:'ffffff',
    length:55
  });
}

function loadNav(){
  $('#nav li a').filter(function (index) {
                  return $(this).attr("id") != "";
                }).each(function(n){
    var idval = $(this).attr('id');
    var altval = $(this).text();
    if(idval != ''){
      $(this).attr('title',altval);
      preloadnavimg[idval] = new Image();
      preloadnavimg[idval].id = idval;
      preloadnavimg[idval].alt= altval;
      preloadnavimg[idval].onload = function(){
        this.onload = null;
        var imgstr = "<img src='../images/nav_"+this.id+".gif' alt='"+this.alt+"'>";
        var aid = '#nav li a#'+this.id;
        $(aid).text('');
        $(imgstr).appendTo(aid);
      }
      preloadnavimg[idval].src = '../images/nav_'+idval+'.gif';
      var subnav = $(this).siblings().filter(function (index) {
                  return $(this).attr("class") == "subnav";
                }).html();
      if(subnav != null){
        var href = $(this).attr('href');
        $(this).removeAttr('href');
        $('#subnav-holder').mouseover(function(){$(this).show()}).mouseout(function(){$(this).hide()});
        $(this).mouseover(function(){
          $('#subnav-holder').html('<ul>'+$(this).siblings().filter(function (index) {
                  return $(this).attr("class") == "subnav";
                }).html()+'</ul>');
          var offset = $(this).offset();
          $('#subnav-holder').css('left',offset.left);
          $('#subnav-holder').show();
        }).mouseout(function(){
          $('#subnav-holder').hide();
        }).click(function(){document.location = href;});
      }
    }  
  });
}

function titliseImageLinks(elements){
  if(!elements){
    elements = 'a';
  }
  $(elements).each(function() {
    var $title = $("img", this).attr("alt");
    if($title != "" && $title != "undefined" && $title != null && $title != "null"){
      $(this).attr("title", $title);
    }
  }); 
}

function setSignupLinks(){
  $('.signup').each(function(){
    $(this).attr('href','https://secure.gunzblazing.com/signup/signup.php?s=56');
    $(this).attr('target', '_top');
    $(this).click(function(){
      try{
        top.frame.exit=false;
      }catch(e){
        
      }
    });
    $(this).attr('class','signup-fixed');
  });
}

function fixVideoLinks(){
  $('.videoLinks').each(function(n){
    var textArray = $(this).text().split(',');
      var vid = textArray[0];
      var title = $(this).attr('title');
      var type =  $(this).attr('alt');
      var fsize = "";
      var dsize = "";
          var tw = "1900";
          var th = "760";
      switch(type){
        case 'h.264_1800_normal':
           var fsize = "wh1800";
           var dsize = "1800";
          var tw = "1900";
          var th = "760";
           break;
        case 'h.264_1800_wide':
           var fsize = "wh1800ws2";
           var dsize = "1800";
          var tw = "1900";
          var th = "760";
           break;
        case 'h.264_1800_wide_HD':
           var fsize = "wh1800ws2hd";
           var dsize = "1800";
          var tw = "1900";
          var th = "760";
           break;
		case "h.264 wide":
			var fsize = "wh1500ws2";
			var dsize = "1500";
          var tw = "1900";
          var th = "760";
			break;
		case "h.264 normal":
    			var fsize = "wh1500";
    			var dsize = "1500";
          var tw = "1900";
          var th = "760";
          break;
        default: 
           break;      
      }
      $(this).text('');
      $(this).removeAttr('title');
      $(this).removeAttr('alt');
      if(fsize != ""){
        switch(textArray[1]){
          case 'home':
            $(this).append('Stream Trailer:&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/38/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">38</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/180/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">180</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/300/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">300</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/768/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">768</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/'+ dsize+'/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">'+ dsize+'</a>&nbsp;|&nbsp;<a href="/tour/play.php?type=dl&path=trailers/' + vid +'-' +dsize+'">Download</a>');
            break;
          case 'section':
            $(this).append('Stream Trailer:&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/38/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">38</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/180/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">180</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/300/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">300</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/768/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">768</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/'+ dsize+'/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">'+ dsize+'</a>&nbsp;|&nbsp;<a href="/tour/play.php?type=dl&path=trailers/' + vid +'-' + dsize+'">Download</a>');
            break;
          case 'gallery':
            $(this).append('Stream Trailer:&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/38/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">38</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/180/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">180</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/300/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">300</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/768/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">768</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/'+ dsize+'/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">'+ dsize+'</a>&nbsp;|&nbsp;<a href="/tour/play.php?type=dl&path=trailers/' + vid +'-' + dsize+'">Download</a>');
            break;
          case 'Brazil':
            break;
          default:
            $(this).append('Stream Trailer:&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/38/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">38</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/180/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">180</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/300/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">300</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/768/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">768</a>&nbsp;<a href="/tour/play.php?type=flv&path=' + vid + '/'+ dsize+'/'+fsize+'?TB_iframe=true&height='+th+'&width='+tw+'" title="'+title+'" class="thickbox">'+ dsize+'</a>&nbsp;|&nbsp;<a href="/tour/play.php?type=dl&path=trailers/' + vid +'-' + dsize+'">Download</a>');
            break;
        }
      }else{
      
      }
      $(this).removeClass('videoLinks').addClass('videoLinks-fixed');
  });
  tb_init('.thumb_link, .thickbox');
}






function openSub() 
{
	
	wWidth = 800; wHeight = 600;
	
	wHPos = (screen.width / 2) - (wWidth / 2);
	wVPos = (screen.height / 2) - (wHeight / 2) - 50;
	
	if (document.all) {
	oWin = self.open("/subscribe/","nvSMP","width="+wWidth+",height="+wHeight+",location=no,top="+wVPos+",left="+wHPos+",personalbar=no,menubar=no,scrollbars=no,status=no,toolbar=no")
	oWin.focus()
	} else {
		oWin = self.open("/subscribe/","nvSMP","width="+wWidth+",height="+wHeight+",location=no,screenY="+wVPos+",screenX="+wHPos+",personalbar=no,menubar=no,scrollbars=no,status=no,toolbar=no")
		oWin.focus()
	}
	
}


function openApp() 
{
	
	wWidth = 800; wHeight = 600;
	
	wHPos = (screen.width / 2) - (wWidth / 2);
	wVPos = (screen.height / 2) - (wHeight / 2) - 50;
	
	if (document.all) {
	oWin = self.open("/feedback/","nvSMP","width="+wWidth+",height="+wHeight+",location=no,top="+wVPos+",left="+wHPos+",personalbar=no,menubar=no,scrollbars=yes,status=no,toolbar=no")
	oWin.focus()
	} else {
		oWin = self.open("/feedback/","nvSMP","width="+wWidth+",height="+wHeight+",location=no,screenY="+wVPos+",screenX="+wHPos+",personalbar=no,menubar=no,scrollbars=yes,status=no,toolbar=no")
		oWin.focus()
	}
	
}

function openChat() 
{
	
	wWidth = 800; wHeight = 515;
	
	wHPos = (screen.width / 2) - (wWidth / 2);
	wVPos = (screen.height / 2) - (wHeight / 2) - 50;
	
	if (document.all) {
	oWin = self.open("cams/","nvSMP","width="+wWidth+",height="+wHeight+",location=no,top="+wVPos+",left="+wHPos+",personalbar=no,menubar=no,scrollbars=no,status=no,toolbar=no")
	oWin.focus()
	} else {
		oWin = self.open("cams/","nvSMP","width="+wWidth+",height="+wHeight+",location=no,screenY="+wVPos+",screenX="+wHPos+",personalbar=no,menubar=no,scrollbars=no,status=no,toolbar=no")
		oWin.focus()
	}
	
}


