
$(document).ready(function(){
  
  if ($('html').hasClass('ie')) isIE = true;
  centerLogin();
  customDropDown();
  
});

function centerLogin() {
  var h = $('#wrapper').height();
  $('#wrapper').css('margin-top', -(h/2))
}

function customDropDown() {
  
  if($("#logo").length == 0) return false;
  
  var links = $("#logo").find('a');
  
  links.click(function(e) {
    e.preventDefault();
    
    setNetwork($(this).attr('rel'));
    
  })

	if($('.customDropDown').length == 0) return false;
	
	var bt_dd        = $('.bt_dd'),
	    ddDivs       = $('.dd'),
	    ddDiv        = $('#' + bt_dd.attr('rel')),
	    list         = ddDiv.find('a'),
	    hidden       = ddDivs.next();
	    

	
	bt_dd.click(function(e) {
		e.preventDefault();
		
		if(list.length > 0) {
		  bt_dd.toggleClass('dd-open');
  		ddDiv.toggle();
  		$('.dd[id!=' + bt_dd.attr('rel') + ']').hide();
		}
	});
	
	list.click(function(e) {
	   e.preventDefault();
	   
	   var item = $(this);
	   
	   list.parent().removeClass('selected');
	   item.parent().addClass('selected');
	   var rel = item.attr('rel');
	   
	   hidden.val(rel);
	   
	   setSelect();
	   bt_dd.text(item.text());
	   $('.dd').hide();
  });

  function setSelect(){

    var selected = $('input[name="network_id"]'),
        li_select = $('.network-' + selected.val()),
        li = $('#logo li');

    li.removeClass("selected");
    if(li_select.length > 0) li_select.addClass("selected");
  }
  
  if(ddDiv.find('.selected').length > 0) {
	  var link = ddDiv.find('.selected a');
	  link.trigger('click');
	}



  function setNetwork(pNetwork) {

    $('input[name="network_id"]').val(pNetwork);
    
    var item = $('a[rel="' + pNetwork + '"]');
    
    list.parent().removeClass('selected');
    item.parent().addClass('selected');
    bt_dd.text(item.text());

  	setSelect();
  }

  /* Click anywhere else on the page closes the customDropDown */
  $(document).click(
    function (e) {      
		  if(!$(e.target).is('.bt_dd') && !$(e.target).parent().is('.bt_dd')) {
		  	$('.dd').hide();
		  	$('.bt_dd').removeClass('dd-open');
		  }
    }
  )
}



 
// Show logos' flash
function showFlashLogos (pFlasvars) {
	document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="350" height="100%" id="logoFlash">');
	document.write ('<param name="movie" value="/assets/flash/logo.swf">');
	document.write ('<param name="quality" value="high">');
	document.write ('<param name="bgcolor" value="#2e2c2d">');
	document.write ('<param name="scale" value="noscale">');
	document.write ('<param name="salign" value="lt">');
	document.write ('<param name="flashvars" value="'+pFlasvars+'">');
	document.write ('<embed src="/assets/flash/logo.swf" quality="high" width="350" height="100%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" name="logoFlash" swLiveConnect="true" flashvars="'+pFlasvars+'" salign="lt" bgcolor="#2e2c2d">');
	document.write ('</embed>');
	document.write ('</object>');
}



function callFlashFunc(movie, strLocation, strFunc, arrArgs, strCallBack) {
	var toggle = movie.GetVariable("jsCallTrigger");
	movie.SetVariable("jsCallFuncLocation", strLocation);
	movie.SetVariable("jsCallFuncName", strFunc);
	movie.SetVariable("jsCallFuncArgs", arrArgs.join(","));
	movie.SetVariable("jsCallFuncCallBack", strCallBack);
	movie.SetVariable("jsCallTrigger", !toggle);
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	} else {
		return document[movieName]
	}
}

var offsetMac = 0;
function openWindow(pUrl,pTitle, pWidth,pHeight,pStyle) {
	var x = 0;
	var y = 0;
	var offset = 30;
		
	if (screen) x = (screen.availWidth - pWidth) / 2;
	if (screen) y = (screen.availHeight - pHeight) / 2;
	
	
	var popped;
	
	if ( pStyle == 'POP' ) { 
	    var popped = window.open(pUrl,pTitle,'width='+pWidth+',height='+(pHeight+offsetMac)+',status=no,menubar=no,scrollbars=no,resizable=no,screenX='+x+',screenY='+y+',left='+x+',top='+y); 
    }
    
	if ( pStyle == 'POPSCROLL' ) { 
	    var popped = window.open(pUrl,pTitle,'width='+pWidth+',height='+(pHeight+offsetMac)+',status=no,menubar=no,scrollbars=auto,resizable=yes,screenX='+x+',screenY='+y+',left='+x+',top='+y); 
    }

	if ( pStyle == 'WINDOW' ) {
		if (pHeight > screen.availHeight) pHeight = (screen.availHeight - offset);
		var popped = window.open(pUrl,pTitle,'width='+pWidth+',height='+(pHeight+offsetMac)+',status=yes,menubar=yes,scrollbars=yes,resizable=yes,screenX='+x+',screenY='+y+',left='+x+',top='+y);
	}
	
	if ( document.all) popped.focus();
	if ( !popped.opener) { popped.opener = window; }
}


