// JavaScript Document

 $('html').addClass('js');

 $(document).ready(function() {
	var clevent = "click"
	var umhtml5 = false;						
	var IsIPhone = false;
     IsIPhone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i));							
	 if(IsIPhone){ 
	 $('#showcase #slider1 li .slideContent').addClass('ipad');
	 clevent = "touchstart";
	 $('#footerlinks').append("<div id='frenchtest'>french</div>");
	 
	 $('#frenchtest').bind(clevent, function(e) {
     vidlanguageid = '55b088f7-ea6b-4af5-81f4-74389368d659'; loadumvideo();
});
	 
	 
	 
	 
	 
	 }
	 var winmobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
	 

 

// Detect Flash ////////////////////////////////////////////////////////////////////////////////
function checkForFlash() {
var obj;
var flashFound = false;

// Flash browser plugin string
var flashPlug = 'application/x-shockwave-flash';

// Flash ActiveX plugin string
var flashActiveX = 'ShockwaveFlash.ShockwaveFlash';

// Check for browser plugin
if (navigator && navigator.plugins && navigator.plugins.length) {
if (navigator.mimeTypes && navigator.mimeTypes[flashPlug]) {
flashFound = true;
}
}

// Check for ActiveX plugin if browser plugin not found
if (!flashFound) {
try{
obj = new ActiveXObject(flashActiveX);
flashFound = true;
} catch(err) {}
}
return flashFound;
}

// Close Detect Flash /////////////////////////////////////////////////////////////////////////

var flashenabled = checkForFlash();
			
	$('#highlight1').load('includes/highlight1.html #hl1');
	$('#highlight2').load('includes/highlight2.html #hl2');
	$('#highlight3').load('includes/highlight3.html #hl3');
	$('#highlight4').load('includes/highlight4.html #hl4');

// Load News
	//$('#news').load('js/news/homenews.html');

	// Load About Us
	$('#aboutus').load('includes/footer_aboutus.html #aboutconent');		
			

// Load home page video	
if(	$('#umvideo').length > 0){
	// Default English Language	
	var vidlanguageid = "65271c57-731b-4d99-9333-be5f9771e0b7";
	var rv = -1; // Return value assumes failure.
  	if (navigator.appName == 'Microsoft Internet Explorer')
  		{
    		var ua = navigator.userAgent;
    		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    		if (re.exec(ua) != null)
      		rv = parseFloat( RegExp.$1 );
  		};
	
function loadumvideo(){		
	if(IsIPhone || rv >= 9.0 || flashenabled == false || winmobile){

	// style html5 players for varience in video display
	$('#showcase').css('height','394px').css('overflow','hidden');
	$('.actionbtns, .actionbtns2').css('top','-50px');
	// $('#umlanguage').css('top','5px').css('left','5px');
		
	umhtml5 = true;
	
	$('#umvideo').html('<video  src="http://once.unicornmedia.com/now/od/auto/2bc2bf67-d196-43a8-aeea-147bf705317b/206d3038-6036-4a46-9e2e-b2cf4f3936e9/'+vidlanguageid+'/content.once" type="video/mp4" autoplay  controls="false" height="395" width="710">');
			//$('#umvideo').load('includes/video_media_management_html5.html #video', function() {
  	}
	else
	{
			$('#umvideo').html('<object id="flashobject"  type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" allowNetworking="all" height="399" wmode="transparent" width="710" data="http://r.unicornmedia.com/content.aspx?uid=AC26FE85-334B-4A21-B72C-154F743F5739&at=206d3038-6036-4a46-9e2e-b2cf4f3936e9"> <param name="quality" value="high" /> <param name="allowFullScreen" value="true" /> <param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent"> <param name="allowNetworking" value="all" /><param name="movie" value="http://r.unicornmedia.com/content.aspx?uid=AC26FE85-334B-4A21-B72C-154F743F5739&at=206d3038-6036-4a46-9e2e-b2cf4f3936e9" /> <param name="flashvars" value="config=http://r.unicornmedia.com/embed/206d3038-6036-4a46-9e2e-b2cf4f3936e9?view=item%26view_id='+vidlanguageid+'" /></object>');
	};
} // end loadumvideo
	
loadumvideo();  
			
if(umhtml5){
	var umhtml5video = document.getElementsByTagName('video')[0];
	
	umhtml5video.onended = function(e) { clicky.video('end', Math.round( umhtml5video.currentTime), 'http://once.unicornmedia.com/now/od/auto/2bc2bf67-d196-43a8-aeea-147bf705317b/206d3038-6036-4a46-9e2e-b2cf4f3936e9/', 'Unicorn Once' ); $('#umvideo').load('includes/video_media_end.html #loadcontent', function() {});}

	umhtml5video.onplay = function(e) { clicky.video('play', Math.round( umhtml5video.currentTime), 'http://once.unicornmedia.com/now/od/auto/2bc2bf67-d196-43a8-aeea-147bf705317b/206d3038-6036-4a46-9e2e-b2cf4f3936e9/', 'Unicorn Once' )}
	umhtml5video.onpause = function(e) { clicky.video('pause', Math.round( umhtml5video.currentTime), 'http://once.unicornmedia.com/now/od/auto/2bc2bf67-d196-43a8-aeea-147bf705317b/206d3038-6036-4a46-9e2e-b2cf4f3936e9/', 'Unicorn Once' )}
	umhtml5video.seeked = function(e) { clicky.video('seek', Math.round( umhtml5video.currentTime), 'http://once.unicornmedia.com/now/od/auto/2bc2bf67-d196-43a8-aeea-147bf705317b/206d3038-6036-4a46-9e2e-b2cf4f3936e9/', 'Unicorn Once' )}

}

$('#english').live('click',(function () { vidlanguageid = '65271c57-731b-4d99-9333-be5f9771e0b7'; loadumvideo();}));
$('#french').bind(clevent,(function (e) { vidlanguageid = '55b088f7-ea6b-4af5-81f4-74389368d659'; loadumvideo();}));
$('#spanish').live('click',(function () { vidlanguageid = '4c07e453-f064-4689-823e-fac8cc4a6ca9'; loadumvideo();}));
$('#german').live('click',(function () { vidlanguageid = 'd7064928-fc7f-4fab-83f2-1af74aa87eeb'; loadumvideo();}));
$('#portugese').live('click',(function () { vidlanguageid = 'c4f853c6-d532-40f4-a534-5dfb67960ab1'; loadumvideo();}));
$('#japanese').live('click',(function () { vidlanguageid = '10619298-d6e7-4a07-aa8d-b41c41fe6025'; loadumvideo();}));			
$('#cantonese').live('click',(function () { vidlanguageid = 'f3bdde50-c7a8-4674-a659-03501d3acf5c'; loadumvideo();}));
$('#mandarin').live('click',(function () { vidlanguageid = '918be0d8-5eb3-46ee-83ee-3921c2dfc86f'; loadumvideo();}));

}

// get rid of skype formatting
 $.geekSkypeRemover(10000);


							
	 // connect social funtions
	 
	var storedTimeoutID;
	var storedTimeoutID2;
	
	 $('#socialbtns img[alt="Twitter"]').live('mouseover',(function () {
		clearTimeout(storedTimeoutID2);
		clearTimeout(storedTimeoutID);
		$("#fblike").hide();
		$("#twitum").show();
		$("#twitopts").slideDown("slow");	
		storedTimeoutID=setTimeout('$("#twitopts").slideUp("slow")', 5000);
		}));

	$('#socialbtns img[alt="Facebook"]').live('mouseover',(function () {
		clearTimeout(storedTimeoutID);
		clearTimeout(storedTimeoutID2);
		$("#twitum").hide();
		$("#fblike").show();
		$("#twitopts").slideDown("slow");
		storedTimeoutID2=setTimeout('$("#twitopts").slideUp("slow")', 5000);
		}));
	
	$('.placard1').live('click',(function(event) {window.location = "http://unicornmedia.com/products_mobile.html";}));
	$('.placard2').live('click',(function(event) {loadumvideo();}));
										  
	$('.1lm').click(function () {window.location = "http://unicornmedia.com/products_mobile.html";});
	$('.2lm').click(function () {window.location = "http://unicornmedia.com/products_monetization.html";});
	$('.3lm').click(function () {window.location = "http://unicornmedia.com/products_analytics.html";});
	$('.9lm').click(function () {window.location = "http://unicornmedia.com/products_mobile.html";});
	$('.4lm').click(function () {window.location = "http://unicornmedia.com/products_asset-management.html";});
	$('#highlight1').live('click',(function(event) {window.location = "http://unicornmedia.com/solutions_publishers-broadcasters.html";}));
	$('#highlight2').live('click',(function(event) {window.location = "http://unicornmedia.com/solutions_aggregators.html.html";}));
	$('#highlight3').live('click',(function(event) {window.location = "http://unicornmedia.com/solutions_ad-networks.html";}));
	$('#highlight4').live('click',(function(event) {window.location = "http://unicornmedia.com/solutions_value-added-resellers.html";}));
	$('#streaming100').live('click',(function () {window.location = "http://www.unicornmedia.com/company_news-and-events.html#news/news/11.10.13_UM_on_StreamingMedia_Top100.html";}));
	$('#followum').live('click',(function () {window.location = "http://twitter.com/unicornmedia/";}));
	$('#umlogo').click(function () {window.location = "http://unicornmedia.com/";});
	
	$('#socialbtns img[alt="linkedIN"]').live('click',(function () {window.location = "http://www.linkedin.com/company/unicorn-media-inc./";}));
	$('#socialbtns img[alt="Facebook"]').live('click',(function () {window.location = "http://www.facebook.com/UnicornMedia";}));
	$('#socialbtns img[alt="RSS"]').live('click',(function () {window.location = "rss/unicorn_media_rss.xml";}));
	$('#eventscontainer').live('click',(function(event) {window.location = "http://unicornmedia.com/company_events.html";}));


      $('#socialbtns img[alt="email"], #emailpage').live('click',(function() {
        var data = {
          title: document.title,
          url: window.location.href,
          nl: "\n" // tmpl seems to each newline chars so we use this instead.
        }
        var url = 'mailto:?Subject=';
        var subject = document.title;
        url += encodeURIComponent(subject);
        url += '&Body=';
        var eBody = "Interesting Information: " + window.location.href;
        url += encodeURIComponent(eBody);
        window.location.href = url;
      }));
	  
	// Add footer links

	$('#footerlinks #newscontainer').load("js/news/homenews.html", function() {
	  //alert('Load was performed.');
	 // $('#footerlinks .ddsmoothmenu').attr( 'id', 'footermenu' );
	});
	$('#footerlinks #eventscontainer').load("company_events.html #umevents", function() {
	  
	  $('#footerlinks #eventscontainer').prepend('<h3>Events</h3>');
	});
	
	$('#footerlinks #resources').load('includes/footer_resources.html');
	
	// Add Developer links
	$('#devlinks').load('includes/developer_links.html');
	//Load Contact Form 
	//$( "#loadcontact_form" ).modal().load("includes/contact_form.html");
	// Click events
	$("#clientLogIn").click(function () {window.open("http://portal.unicornmedia.com/");return false;
});


	$("#clientHelp").click(function () {window.open("http://support.unicornmedia.com/access/unauthenticated?return_to=http%3A%2F%2Fsupport.unicornmedia.com%2F");return false;
});

	$("#clientContact, #freetrial, #btnRequestDemo, #mainmenucontact, .mContactUs, #joinus, .supportcontact, #showcasefreetrial, #showcasecontact, #subfreetrial, #subcontact, #subrequestdemo, #requestdemoinline, #contactusinline").live('click',function () {
			var 	objid = $(this).attr("id");	
			
		$("#loadcontact_form").modal({
			minHeight:525,
			minWidth: 790,
			onShow: function (dialog) {
				$( "#loadcontact_form" ).load("includes/contact_form.html", function(){
																					 
								if(objid=="joinus"){ $('#contact_purpose').val('Business Development and Partnerships');}
								if(objid=="subcontact" || objid=="salessupport"){ $('#contact_purpose').val('General Sales');}
								if(objid=="contactusinline" ){ $('#contact_purpose').val('Event Information');}
								if(objid=="freetrial" || objid=="subfreetrial" || objid=="showcasefreetrial"){$('#contact_purpose').val('Request a Free Trial');}
								if(objid=="btnRequestDemo" || objid=="subrequestdemo" || objid=="requestdemoinline" || objid=="showcasecontact"){ $('#contact_purpose').val('Request a Demo');}
								$('#cforminfo').load("includes/contact_block.html", function(){
									$( "#contactForm" ).height($('#cforminfo').height()+ 58 );
									$( "#simplemodal-container" ).height($( "#contactForm" ).height()+ 15 );
								});													 
					});
				
			}});									
										
	});
	
/***********************************************
* Email list sign-up
***********************************************/
$("#emailForm").live('submit',function(e) {
								  
    	e.preventDefault();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		$("#aboutus .error").remove();
		if($("#emaillist").val() == '') {
            $(".header.mt10").append('<span class="error">  Please enter your email address.</span>');
            return false;
        } else if(!emailReg.test($("#emaillist").val())) {
            $(".header.mt10").append('<span class="error">  Please enter valid address.</span>');
            return false;
        }
			
			alert($(this).attr('action'));
    			$.post( "submitToListKG.aspx", $(this).serialize(), 
                	function(resp) {
						
                    	if(resp == "success") {
                        alert(resp);
						
						 $('#emaillist.umhmtxt').val('Thank you.');

						
                    	} else {
                        // something else
						//alert("error");
						$('#emaillist').val('Sorry there was a problem.');
                   		}
                	});
				
			//stay on the page
			return false;
			});
/***********************************************
* END Email list sign-up
***********************************************/	
	
	

});

/***********************************************
* Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
ddsmoothmenu.init({
	mainmenuid: "ummenu1", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	contentsource: ["ummenucontainer", "includes/main_menu.html"] //"markup" or ["container_id", "path_to_menu_file"]
})
