function AsusInteractive(element) {
	var self = this;
	this.root = element;
	//var mapOpen = false;


	this.initalize = function() {

	    $(".extraContent").animate({ left: '300', opacity: 0 }, 100);

	    $('#loopedSlider').loopedSlider({
	        containerClick: false
	    });



	    $(".moreButton").click(function() {
	        var slideID = $(this).parent().parent().parent().attr('id');
	        var columnID = $(this).parent().attr('class');
	        var panelID = slideID + columnID + 'Panel';
	        $("#" + panelID).css("display", "block");
	        $("#" + panelID).animate({ left: '0', opacity: 1 }, 500);
	    });

	    $(".close").click(function() {
	        var panelID = $(this).parent().attr('id');
	        $("#" + panelID).animate({ left: '300', opacity: 0 }, 500, 'linear', function() { $("#" + panelID).css("display", "none"); });
	    });

	    var overlayClone;

	    // At end of video, displays overlay that allows user to replay video or link elsewhere.
	    // Sets replay link, shows appropriate full movie link.
	    showVideoOverlay = function(playerId) {

	        var playerObj = $("#" + playerId);

	        // if the overlay hasn't already been appended, do it
	        if ($(playerObj).parent().find("div").length == 0) {

	            // clone video overlay from BODY
	            overlayClone = $(".videoOverlay").clone();

	            // set click function
	            $(overlayClone).find(".replay").unbind("click");
	            $(overlayClone).find(".replay").click(function(e) {
	                e.preventDefault();
	                $(this).blur();
	                player.sendEvent("PLAY", "true");
	            });

	            // append clone
	            $(playerObj).parent().append($(overlayClone));
	        }

	        $(overlayClone).fadeIn();
	    }

	    hideVideoOverlay = function() {
	        $(overlayClone).hide();
	    };

	    // this function ensures that the modal appears at correct size without scrollbars
	    // even when the browser window is too small for it to fit
	    function resizeModal(modalObj) {
	        $("#simplemodal-container").css("width", $(modalObj).css("width"));
	        $("#simplemodal-container").css("height", $(modalObj).css("height"));
	        $("#simplemodal-container .simplemodal-wrap").css("overflow", "hidden")
	    }

	    // open modal window on click
	    $(".thumbnail").click(function(e) {
	        var isIphoneOrIpod = DetectIphoneOrIpod();
	        var isAndroid = DetectAndroid();
	        var model = GetCurrentModel();
	        if (isIphoneOrIpod) {
	            var filePath = GetIphoneTrailer(model);
	            window.location = filePath;
	        }
	        else if (isAndroid) {
	            var filePath = GetAndroidTrailer(model);
	            window.location = filePath;
	        }
	        else {
	            $("#modalVideo").modal({
	                opacity: 70,
	                overlayCss: { backgroundColor: "#000" },
	                overlayClose: true
	            });
	            resizeModal($("#modalVideo"));
	        }
	    });

	    // determine model from classname and initialize player
	    var model;
	    if ($("#modalVideo").hasClass("modalVideoG")) {
	        model = "G";
	    } else if ($("#modalVideo").hasClass("modalVideoN")) {
	        model = "N";
	    } else if ($("#modalVideo").hasClass("modalVideoU")) {
	        model = "U";
	    }
	    initPlayer(model);

	    // grabs a query variable
	    function getQueryVariable(variable) {
	        var query = window.location.search.substring(1);
	        var vars = query.split("&");
	        for (var i = 0; i < vars.length; i++) {
	            var pair = vars[i].split("=");
	            if (pair[0] == variable) {
	                return pair[1];
	            }
	        }
	        //alert('Query Variable ' + variable + ' not found'); 
	    }

	    // if "model" was designated as query variable, select that model
	    var showvideo = getQueryVariable("showvideo");

	    if (showvideo == "true") {
	        var isIphoneOrIpod = DetectIphoneOrIpod();
	        var isAndroid = DetectAndroid();
	        var model = GetCurrentModel();
	        if (isIphoneOrIpod || isAndroid) {
	            alert("To view the full video, click the image with the play button.");
	        }
	        else {
	            $("#modalVideo").modal({
	                opacity: 70,
	                overlayCss: { backgroundColor: "#000" },
	                overlayClose: true
	            });
	            resizeModal($("#modalVideo"));
	        }
	    }

	}
	
	self.initalize();

}

function GetCurrentModel() {
    // determine model from classname
    var model;
    if ($("#modalVideo").hasClass("modalVideoG")) {
        model = "G";
    } else if ($("#modalVideo").hasClass("modalVideoN")) {
        model = "N";
    } else if ($("#modalVideo").hasClass("modalVideoU")) {
        model = "U";
    }
    return model;
}

function GetAndroidTrailer(model) {
    var path = window.location.pathname.split("index.html").slice(0)[0];
    var filePath = 'http://' + window.location.host + path + 'mobilemedia/ASUS_' + model + '_SERIES.3gp';
    return filePath;
}

function GetIphoneTrailer(model) {
    var path = window.location.pathname.split("index.html").slice(0)[0];
    var filePath = 'http://' + window.location.host + path + 'mobilemedia/ASUS_' + model + '_SERIES.m4v';
    return filePath;
}

var showVideoOverlay;
var hideVideoOverlay;

// When video is complete, show overlay. When video plays, hide overlay.
function jwplayerMediaComplete(obj) {
	if (obj.newstate == "COMPLETED") {
		showVideoOverlay(obj.id);
	} else if (obj.newstate == "PLAYING") {
		hideVideoOverlay();	
	}
}

var player;

// when player is loaded, create a handle to the player and create an onComplete event
function playerReadyCallback(obj) {
	player = document.getElementById(obj['id']);
	player.addModelListener( "STATE", "jwplayerMediaComplete" );
	//player.sendEvent("PLAY","true");
};

// initialize JW player
function initPlayer(model) {
	var folder;
	if (model == "G") {
		folder = "game";
	} else if (model == "N") {
		folder = "multimedia";
	} else if (model == "U") {
		folder = "style";
	}
	var path = window.location.pathname.split("index.html").slice(0)[0];
	var filePath = 'http://'+window.location.host+path+'flv/ASUS_'+model+'.flv';
	//var filePath = 'file://'+window.location.host+path+'flv/ASUS_'+model+'.flv';		// local testing only
	
	var so = new SWFObject('../media/player.swf', 'fullVideo', 864, 510, '9', '../media/expressInstall.swf');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	//so.addParam('wmode','opaque');
	so.addParam('wmode','transparent');
	so.addVariable('playerready','playerReadyCallback');
	so.addVariable('autostart','true');
	so.addVariable('file', filePath);
	so.addVariable('plugins', 'gapro-1');
	so.addVariable('gapro.accountid', 'UA-15348783-1');
	so.write('modalVideoContainer');
	
}
