

function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

var req;
function loadXMLDoc( url, outbin, pageRequest ){
	req = false;
	if( typeof XMLHttpRequest != "undefined" ){
		req = new XMLHttpRequest();
	}
	else if( typeof window.ActiveXObject != "undefined" ){
		try{
			req = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		}
		catch( e ){
			try{
				req = new ActiveXObject("MSXML2.XMLHTTP");
			}
			catch( e ){
				try{
					req = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch( e ){
					req = null;
					document.getElementById(outbin).innerHTML = "Your browser can\'t handle this script\n";
					return;
				}
			}
		}
	}
	if( req ){
		req.onreadystatechange = function(){ processReqChange( outbin, pageRequest ); };
		req.open( "GET", url, true );
		req.send( "" );
	}
}

function processReqChange( outbin, searchTerm ){
	if( req.readyState == 4 ){
		if( req.status == 200 ){
			doc = req.responseXML;
			dumpStuff = "";
			alert( doc );
			/*if ( searchTerm != "" ){
				for( i=0; (group = doc.getElementsByTagName("group")[i]); i++ ){
					if( group.getAttribute("id") == searchTerm ){
						dumpStuff += "<h3>" + group.getAttribute("title") + "</h3>\n";
					}
				}
			}
			for( i=0; (customer = doc.getElementsByTagName("customer")[i]); i++ ){
				with (customer) {
					if ( searchTerm != "" ) {
						if ( getAttribute("group") == searchTerm ) {
							dumpStuff += "<a href=\""+getAttribute("url")+"\" target=\"_blank\" class=\"customer\"><img src=\""+getAttribute("logo")+"\" alt=\"Company logo\"/></a>\n";
						}
					}
					else {
						dumpStuff += "<a href=\""+getAttribute("url")+"\" target=\"_blank\" class=\"customer\"><img src=\""+getAttribute("logo")+"\" alt=\"Company logo\"/></a>\n";
					}
				}
			}
			document.getElementById(outbin).innerHTML = dumpStuff;*/
		}
		else{
			document.getElementById(outbin).innerHTML = "There was a problem retrieving the XML data:\n" + req.statusText;
		}
	}
}

function fade(){
	if ( outControl - parseFloat(1/10) >= 0 ){
		inControl += parseFloat(1/10);
		newsItems[controlIn].style.opacity = inControl.toFixed(1);
		newsItems[controlIn].style.filter = 'alpha(opacity=' + inControl.toFixed(1)*100 + ')';
		outControl -= parseFloat(1/10);
		newsItems[controlOut].style.opacity = outControl.toFixed(1);
		newsItems[controlOut].style.filter = 'alpha(opacity=' + outControl.toFixed(1)*100 + ')';
		setTimeout("fade()", 30);
	}
	else{
		inControl = 0;
		outControl = 1;
		newsItems[controlOut].style.zIndex --;
		newsItems[controlIn].style.zIndex ++;
		if( newsItems.length-1 > controlIn ) controlIn++;
		else controlIn = 0;
		if( newsItems.length-1 > controlOut ) controlOut++;
		else controlOut = 0;
	}
}


function set_cookie ( name, value, expires, path, domain, secure ){
  var cookie_string = name + "=" + escape ( value );
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires ) {
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	cookie_string += "; expires=" + expires_date.toGMTString();

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  document.cookie = cookie_string;
}






window.onload = function(){
		
	if(document.getElementById('regionSelector')) {
    	var div = document.getElementById('regionSelector').getElementsByTagName('div');
		for(i=0;i<div.length;i++) {
		  div[i].onmouseover = function() {
			this.className = 'menuItem over';
		  }
		  div[i].onmouseout = function() {
			this.className = 'menuItem out';
		  }
		  if (div[i].id == 'caLink') {
			  div[i].onclick = function() {
				set_cookie('region', 'CA', 30, '', '.theflip.com', '');
				document.location = 'http://www.theflip.com/en-ca/';
		  	}			  
		  }
		  if (div[i].id == 'usLink') {
			  div[i].onclick = function() {
				set_cookie('region', 'US', 30, '', '.theflip.com', '');
				document.location = 'http://www.theflip.com';
		  	}			  
		  }
		  if (div[i].id == 'ukLink') {
			  div[i].onclick = function() {
				set_cookie('region', 'UK', 30, '', '.theflip.com', '');
				document.location = 'http://flipvideo.co.uk';
		  	}			  
		  }
		}
		
	}


	if (typeof jQuery != 'undefined'){
		function showBubble(){ $(this).parent().parent().parent().find(".mino_personalized_blurb_holder").css("display","block"); }
		function hideBubble(){ $(this).parent().parent().parent().find(".mino_personalized_blurb_holder").css("display","none"); }
		$(document).ready(function(){
			var config = {
					sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
					interval: 400, // number = milliseconds for onMouseOver polling interval
					over: showBubble, // function = onMouseOver callback (REQUIRED)
					timeout: 0, // number = milliseconds delay before onMouseOut
					out: hideBubble // function = onMouseOut callback (REQUIRED)
				};
				$(".mino_personalized a").hoverIntent( config );
		});
	}
	
}


