// JavaScript Document

 $('html').addClass('js');

 $(document).ready(function() {
							
	var IsIPhone = false;
         IsIPhone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i));							
							
	$('#slider1') // Demo 2 code, using FX base effects
	  .anythingSlider({
	   startPanel          : 2,
	   width               : 999,
	   height              : 358,
	   startStopped        : true,
	   delay               : 10000, 
	   autoPlay            : true,
	   pauseOnHover        : true,
	   forwardText         : "&raquo;", 
  backText            : "&laquo;",
	   resumeOnVideoEnd    : true,
	   resizeContents      : false,
	   buildArrows		   : false,
	   navigationFormatter : function(i, panel){
		return ['','<span id="nudge1">Media<br />Management&nbsp;</span>', 'Mobile&nbsp;', 'Analytics&nbsp;', 'Syndication&nbsp;', 'Monetization&nbsp;', 'Workflow Tools&nbsp;'][i - 1];
	   },
	   onSlideComplete : function(slider){
  //alert('Welcome to Slide #' + slider.currentPage);


		
		Pause('flashobject');


  if(slider.currentPage=='2'){
	  clearInterval(slidetimer);
	   var slidetimer = setInterval(function() {
    $('#slider1').trigger('mouseleave');
  }, 65000); 
	  
	  
	  $('#slider1').trigger('mouseover');
  
  
  
  };
  }
	  })
	  
	  $('#slider1 .slideContent, #slider1 .arrow_indicator').css('display','block');
	  


	  
	 if(IsIPhone){ $('#showcase #slider1 li .slideContent').addClass('ipad');}
	 
			
	$('#highlight1').load('includes/highlight1.html #hl1');
	$('#highlight2').load('includes/highlight2.html');

// Load News
	$('#highlight3').load('js/news/homenews.html');

	// Load About Us
	$('#aboutus').load('includes/footer_aboutus.html #aboutconent');		
			
			
	// Load home page video	
	
	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 );
  	}
	
		
	if(IsIPhone){
		$('.embedvideo').load('includes/kvideo_media_management_idevice.html #video');}
		else if(rv >= 9.0)
		{$('.embedvideo').load('includes/kvideo_media_management_ie.html #video');}
		else{$('.embedvideo').load('includes/kvideo_media_management.html #video');};
	
 //if(IsIPhone){}else{
//$('.embedvideo2').load('includes/video_home_flash.html #video');}
			
			
			
			
							

	  
// Link Slides
//$('.panel2 .slideContent').click(function () {window.location = "platform_overview.html";});
$('.panel3 .slideContent').click(function () {window.location = "platform_mobile-delivery.html";});	 
$('.panel4 .slideContent').click(function () {window.location = "platform_analytics.html";});	
$('.panel5 .slideContent').click(function () {window.location = "platform_syndication.html";});	
$('.panel6 .slideContent').click(function () {window.location = "platform_monetization.html";});	
$('.panel7 .slideContent').click(function () {window.location = "platform_mobile-delivery.html";});	

$('#panel1link2').click(function () {window.location = "http://www.streamingmedia.com/Webevents/384-HTML5-Super-Session-Leadership-Roundtable.htm";});
  
// get rid of skype formatting
 $.geekSkypeRemover(10000);


	// Load Highlights under showcase

							

 
	 // 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);
		}));
	
	$('#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";}));



      $('#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').load("includes/main_menu.html", function() {
	  //alert('Load was performed.');
	  $('#footerlinks .ddsmoothmenu').attr( 'id', 'footermenu' );
	});
	
	// 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.unicornmediabeta.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, #panel1link1, #panel1link3").live('click',function () {
			var 	objid = $(this).attr("id");						
		$("#loadcontact_form").modal({
			minHeight:460,
			minWidth: 790,
			onShow: function (dialog) {
				$( "#loadcontact_form" ).load("includes/contact_form.html", function(){
																					 
								if(objid=="joinus"){ $('#contact_purpose').attr('selectedIndex', 6);}
								if(objid=="freetrial"){ $('#contact_purpose').attr('selectedIndex', 2);}
								if(objid=="btnRequestDemo"){ $('#contact_purpose').attr('selectedIndex', 1);}
								$('#cforminfo').load("includes/contact_block.html");													 
					});
				
			}});									
										
	});
	
/***********************************************
* 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"]
})
