$(function(){
		
	//detect browser old!
	if ($.browser.msie && $.browser.version<=7)
	{
		$("#oldBrowser").show();
		bVer = "Internet Explorer v." + $.browser.version;
		$("#oldBrowser .ver:first").html( bVer );	
	}
	
	//set tabPage with
	$(".tabPage").each(function(i,el){
		var w = $(el).parent().parent().width();
		$(el).css({width: w+"px"});
	});
	$(".tabScroller").each( function(i,el){
		//set width
		var c = $(".tabPage", el).length;
		var tW = $(".tabPage:first", el).width();
		var w = c * tW;
		$(el).css({width: w +"px"});
	});
	
	
	$("#menuContainer .mainMenuItem").hover( mnuHoverIn , mnuHoverOut );
	
	function mnuHoverIn(e)
	{
		var p = $(this);
		p.css({ height: "500px"});
		p.find(".backdrop:first").stop(true,false).clearQueue().animate( {top:"10px"}, 400, "easeOutExpo");
		p.find(".title:first").stop(true,false).clearQueue().animate( {color:"#fff"}, 400, "easeOutExpo");
		p.find(".hoverArea:first").show();
		showSubMenu($(this).attr("mnuId"));
	}
	
	function mnuHoverOut(e)
	{
		var p = $(this);
		p.css({ height: "130px"});
		p.find(".backdrop:first").stop(true,false).clearQueue().animate({top:"110px"}, 400, "easeOutExpo");
		p.find(".title:first").stop(true,false).clearQueue().animate( {color:"#6D6E71"}, 400, "easeOutExpo");
		p.find(".hoverArea:first").hide();
		hideSubMenu($(this).attr("mnuId"));
	}
	
	//menuItem hover
	$(".mnuSubItem .content .mnuLink").hover( mnuLinkBackdropShow, mnuLinkBackdropHide );
	$("#sideMenu .mnuLink").hover( mnuSideLinkBackdropShow, mnuSideLinkBackdropHide);
	
	
	
	//tabs
	$("#menuContainer .menuTabs .menuTabItem").click( showMenuTabPage );
	$("#sideMenu .menuTabs .menuTabItem").click( showSideMenuTabPage );
	
	setTimeout( 
	function(){
		//do this for css to be applied.
		//set heightlight Tab color
		$(".menuTabs").each(function(i,el){
			
			if ($(el).find(".tabSelected").length==0)
				$(el).find(".label:first").addClass("tabSelected");			
		});
		
		$("#menuContainer .tabSelected, #sideMenu .tabSelected").each( function(i,el)
		{
			var bgColor = $(el).parent().parent().parent().parent().find(".h2Spacer:first").css("background-color");
			$(el).css({"background-color":bgColor});
			
			var p = $(el).parent();
			
			var idx = $(".menuTabItem", p.parent() ).index( p );
			var pos = (-1) * idx * p.parent().parent().find(".tabPage:first").width();
			
			//console.log( pos );
			p.parent().parent().find(".tabScroller:first").css({left:pos+"px"});
	
		});
		
		//side menu tabcolor and selection
		
		
		//set init arrow colors
		$(".mnuLink a .arrow").each( function (i,el) { $(el).attr("initCol", $(el).css("color") ); } );
	}, 200);
	
	//feat bros and demos
	$("#fotterOver a[class='lnkHomeFeatBros'], #serviceContainer a[class*='iconBros'], #viewAllContainer a[class='lnkAllBros']").click(
		function(e)
		{
			e.preventDefault();
			var src = $(this).attr("href");
			var cnt = '<iframe width="98%" height="98%" src="' + src + '"></iframe>';
			$.fancybox({content: cnt, autoScale:false, autoDimensions:false, width: 800, height: 650});
		}
	).fancybox();
	
	$("#fotterOver a[class*='lnkHomeFeatDemo'], #serviceContainer a[class*='iconVideo'], #viewAllContainer a[class='lnkAllDemos']").click(
		function (e)
		{
			e.preventDefault();
			var did = $(this).attr("did");
			
			$.fancybox({
					'padding'		: 0,
					'autoScale'		: true,
					'autoDimensions' : false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'width'			: 900,
					'height'		: 500,
					'href'			: "resources/VoicewebServiceDemoPlayer.swf",
					'type'			: 'swf',
					'swf'			: {
						'wmode'		: 'opaque',
						'allowfullscreen'	: 'true',
						'flashvars' : 'id=' + did
					}
				});			
		});
})

function showSideMenuTabPage(e)
{
	$(this).parent().find(".tabSelected").removeClass("tabSelected");
	
	//var bgColor = $(this).parent().parent().find(".h2Spacer:first").css("background-color");
	
	$(this).find(".label:first").addClass("tabSelected");//.css({"background-color":bgColor});
	
	//get index
	var idx = $(".menuTabItem", $(this).parent()).index( $(this) );
	var pos = (-1) * idx * $(this).parent().parent().find(".tabPage:first").width();
	
	$(this).parent().parent().find(".tabScroller:first").animate({left:pos+"px"}, 200, "easeInOutQuad");
}

function showMenuTabPage(e)
{
	$(this).parent().find(".tabSelected").removeClass("tabSelected").css({"background-color":""});
	var bgColor = $(this).parent().parent().find(".h2Spacer:first").css("background-color");
	
	$(this).find(".label:first").addClass("tabSelected").css({"background-color":bgColor});
	
	//get index
	var idx = $(".menuTabItem", $(this).parent()).index( $(this) );
	var pos = (-1) * idx * $(this).parent().parent().find(".tabPage:first").width();
	
	$(this).parent().parent().find(".tabScroller:first").animate({left:pos+"px"}, 200, "easeInOutQuad");
}



function mnuLinkBackdropShow (e)
{
	var bd = $(this).find(".linkBackdrop:first");
	bd.stop(true,true).clearQueue().show().animate({width: $(bd).parent().width() + "px"}, 300, "easeInOutQuad" );
	//arrow
	$(this).find(".arrow:first").stop(true,true).clearQueue().animate({color:"#fff"}, 200);
	$(this).find("a:first").stop(true,true).clearQueue().animate({color:"#fff"}, 200);
}

function mnuLinkBackdropHide(e)
{
	var bd = $(this).find(".linkBackdrop:first");
	bd.stop(true,true).clearQueue().animate({width: 0 + "px"}, 300, "easeInOutQuad", function(){ bd.hide(); } );
	
	var finCol = $(this).find(".arrow:first").attr("initCol");
	
	$(this).find(".arrow:first").stop(true,true).clearQueue().animate({color:finCol}, 200);
	$(this).find("a:first").stop(true,true).clearQueue().animate({color:"#BCBEC0"}, 200);
}

function mnuSideLinkBackdropShow (e)
{
	var bd = $(this).find(".linkBackdrop:first");
	bd.stop(true,true).clearQueue().show().animate({width: $(bd).parent().width() + "px"}, 300, "easeInOutQuad" );
	//arrow
	$(this).find(".arrow:first").stop(true,true).clearQueue().animate({color:"#fff"}, 200);
	$(this).find("a:first").stop(true,true).clearQueue().animate({color:"#fff"}, 200);
}

function mnuSideLinkBackdropHide(e)
{
	var bd = $(this).find(".linkBackdrop:first");
	bd.stop(true,true).clearQueue().animate({width: 0 + "px"}, 300, "easeInOutQuad", function(){ bd.hide(); } );
	
	var finCol = $(this).find(".arrow:first").attr("initCol");
	
	$(this).find(".arrow:first").stop(true,true).clearQueue().animate({color:finCol}, 200);
	$(this).find("a:first").stop(true,true).clearQueue().animate({color:"#6D6E71"}, 200);
}

function showSubMenu(mnuId)
{
	$("#" + mnuId).stop(true,true)
				.clearQueue()
				.show()
				.animate({height:"300px"}, 800, "easeInOutQuart", 
				function(){
					$("#" + mnuId).find(".bgWhite:first").stop(true,false).clearQueue().fadeIn(150);
					$("#" + mnuId).find(".mnuContentContent:first").stop(true,false).clearQueue().fadeIn(150);
				}
	);
}

function hideSubMenu(mnuId)
{
	//$("#" + mnuId).find(".bgWhite:first").stop(true,true).clearQueue().fadeOut("fast");
	//$("#" + mnuId).find(".mnuContentContent:first").stop(true,true).clearQueue().fadeOut("fast");
	$("#" + mnuId).stop(true,false).clearQueue().animate({height:"1px"}, 400, "easeOutExpo", function(){ $("#"+mnuId).hide(); });
}

/*!
 * jQuery Platform Plugin.
 * https://github.com/jvduf
 *
 * Copyright 2011 Jeroen van Duffelen (@jvduf)
 * Released under MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Inspired by Sencha Touch by Sencha - http://sencha.com
 */
 (function($) {


    jQuery.extend({
        platform: function(options) {
            var me = this,
            platformData = $(window).data('platform');

            // Check if platformData is already defined on the window,
            // if returns true do not do the platform check but return
            // the data.
            if (platformData) {
                return platformData;
            };

            // Attach platform data to the window;
            $(window).data('platform', {});
            platformData = $(window).data('platform');

            // Define the platforms to check for.
            var platforms = [
            {
                property: 'platform',
                regex: /iPhone/i,
                identity: 'iPhone'
            },
            {
                property: 'platform',
                regex: /iPod/i,
                identity: 'iPod'
            },
            {
                property: 'userAgent',
                regex: /iPad/i,
                identity: 'iPad'
            },
            {
                property: 'userAgent',
                regex: /Blackberry/i,
                identity: 'Blackberry'
            },
            {
                property: 'userAgent',
                regex: /Android/i,
                identity: 'Android'
            },
            {
                property: 'platform',
                regex: /Mac/i,
                identity: 'Mac'
            },
            {
                property: 'platform',
                regex: /Win/i,
                identity: 'Windows'
            },
            {
                property: 'platform',
                regex: /Linux/i,
                identity: 'Linux'
            }
            ];

            var ln = platforms.length,
            i,
            platform;

            navigator = navigator || window.navigator;

            // Loop through all the defined platforms and do a regex
            // test on the platform string to define which platform
            // is being used.
            for (i = 0; i < ln; i++) {
                platform = platforms[i];

                var platformIdentity = platform.identity;

                platformData[platformIdentity] = (platform.regex.test(navigator[platform.property])) ? platformIdentity: false;
            };

            // Based on the platform, define the device type.
            platformData['desktop'] = (platformData['Mac'] || platformData['Windows'] || (platformData['Linux'] && !platformData['Android'])) ? 'desktop': false;
            platformData['tablet'] = (platformData['iPad']) ? 'tablet': false;
            platformData['phone'] = (!platformData['desktop'] && !platformData['tablet']) ? 'phone': false;
            platformData['iOS'] = (platformData['iPhone'] || platformData['iPad'] || platformData['iPod']) ? 'iOS': false;

            // Define if this is opened as a standalone app on iOS.
            platformData['standalone'] = !!window.navigator.standalone;

            return platformData;
        }
    });


})(jQuery);
