// JavaScript Document

function isiPad(){
    return (navigator.platform.indexOf("iPad") != -1);
}

$(document).ready(function () {



    $(".tweet").tweet({
        username: "FullsixGroup",
        avatar_size: 48,
        count: 1,
        loading_text: "loading tweets..."
    });

    $(window).resize(function () {
        windowWidth = $(window).width();
        witdhWindow(windowWidth)
    });

    var windowWidth = $(window).width();
    witdhWindow(windowWidth)

    //getTwitters('tweets', { 
    //		id: 'FullsixGroup', 
    //		count: 1,
    //		enableLinks: true, 
    //		ignoreReplies: false,
    //		template: '%text% <a href="http://twitter.com/%user_screen_name%" target="_blank">#%user_screen_name%</a>'
    //		
    //	//	template: '"%text%" <div>Posted <a href="http://twitter.com/%user_screen_name%">%time%</a>'
    //	});


    /****************
    ################# WHEN SCROLL THE REST OF THE FOOTER APPEARS ################# 
    ****************/
    /*$(window).scroll(function(){
    openAndCloseFooterWithScroll();
    });*/

    // For use within normal web clients 
    var isiPad = navigator.userAgent.match(/iPad/i) != null;

    // For use within iPad developer UIWebView
    // Thanks to Andrew Hedges!

    //var ua = navigator.userAgent;
    //var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
    var isiPad = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i))

    //alert(isiPad);

    var iPreviousScroll = 0;
    if (!isiPad) {
        $('.footerDinamic').attr('style', 'display:block');
        $(window).scroll(function () {
            var iCurrentScroll = $(this).scrollTop();
            var sDir;
            if (iCurrentScroll >= iPreviousScroll) {
                sDir = 'down';
            } else {
                sDir = 'up';
            }
            iPreviousScroll = iCurrentScroll;
            openAndCloseFooterWithScroll(sDir, iPreviousScroll);
        });
    } else {
        $('.bgWithMap').attr('style', 'background:url(/images/backgrounds/bg_home-ipad.gif) no-repeat center top;');
        $('.footerStatic').attr('style', 'width:1032px');
    }



    $('.externalLinks li:first').addClass('backgroundNone');
    /*$('.externalLinks li#country').addClass('paddingRightZero');*/
    $('.menu li:last').addClass('marginRightZero');
    $(".watch li:last").addClass('marginRightZero');
    $(".latest li:last").addClass('marginRightZero');
    $(".trends li:last").addClass('marginRightZero');
    $('.footerPart1 .shareIcons ul li:last').addClass('marginRightZero');

    $(".footerPart2  li:first").css('margin-left', '0px');

    $('.contentNews span:last').addClass('marginBottomZero');
    $(".caseStudies li:last").addClass('marginRightZero');


    //	/*POPIN MOVIE PLAYER AND SLIDE SHARE*/
    //	popinSlideShare();
    //	 
    //	/*CLOSE POPIN MOVIE PLAYER AND SLIDE SHARE*/
    //	closeSlideShare();

    /*CLICK SHARELINK APPEARS THE ICONS TO SHARE*/
    $('.shareLink').click(function () {
        $(this).parent('cite').find('.iconsShare').toggle('slow');
    });


    //IF INPUT TYPE TEXT EXIST INIT DEFAULT VALUE FUNCTION
    if ($('input[type="text"]').length) {
        initInputValue();
    }

    //TIRA O MARGIN EM MULTIPLOS DE 3 
    if ($('.ourNetwork').length) {
        $('.ourNetwork em:nth-child(3n+1)').addClass('marginRightZero');
        
    }

    //TIRA O MARGIN EM MULTIPLOS DE 3 
    if ($('.caseStudies').length) {
        $('.caseStudies li:nth-child(3n)').addClass('marginRightZero');
    }

    //TIRA O MARGIN EM MULTIPLOS DE 3 
    if ($('.contentContacts').length) {
        $('.contact:nth-child(3n)').addClass('marginRightZero');
    }

    //FUNCTION TO PUT THE TABS WORKING
    if ($('.mainContact').length) {
        tabsContact();
    }


    if (($('#map').length) || ($('.mainContact').length)) {
        navigateBetweenPages('tab');
    }
    if ($('.layerActivies').length) {
        $('.imagesActivities li:last').addClass('marginRightZero');
    }


    $('.news h3 a').hover(
  		function () {
  		    $(this).parents('.news').find('span a').css('color', '#ff8200');
  		},
  		function () {
  		    $(this).parents('.news').find('span a').css('color', '#000000');
  		}
	);

    $('.news span a').hover(
  		function () {
  		    $(this).parents('.news').find('h3 a').css('color', '#ff8200');
  		},
  		function () {
  		    $(this).parents('.news').find('h3 a').css('color', '#000000');
  		}
	);

    //$('.externalLinks li:nth-child(3)').css('display', 'none');


    $("#various3").fancybox({
        'width': 940,
        'height': 544,
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });

    /*FUNCTION TO PUT THE ASIDE HEIGTH = SECTIONHOME HEIGHT -> align contact us to the bottom*/
    var height1 = $('.sectionHome').height();
    var height2 = $('.aside').height();
    var height3 = $('.sectionNews').height();


    if (height1 > height2)
        $('.aside').css('height', height1);
    else
        $('.sectionHome').css('height', height2);

    /*NEWS*/
    if (height3 > height2)
        $('.aside').css('height', height3);
    else
        $('.sectionNews').css('height', height2);




});




 /* Fancybox popup if ie6 */


$(document).ready(function () {


       if ($.client.browser == 'Explorer' && $.client.browserversion == '6') {

            $("a#hiddenclicker").fancybox({
                'width': 800,
                'height': 400,
                'autoScale': false,
                'transitionIn': 'none',
                'transitionOut': 'none',
                'type': 'iframe'
            });

            $("a#hiddenclicker").trigger('click');

        }
});


 /* JQUERY CLIENT DETECT BROWSER */
  /*http://www.stoimen.com/blog/2009/07/16/jquery-browser-and-os-detection-plugin/
  USAGE
  $('#os').html("Your browser is running on: <b>" + $.client.os + "</b>");
  $('#browser').html("Your browser is: <b>" + $.client.browser + "</b>");
  $('#browserVersion').html("Your browser is: <b>" + $.client.browserversion + "</b>");*/
 (function () {
  var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) {
  for (var i = 0; i < data.length; i++) {
  var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) {
  if (dataString.indexOf(data[i].subString) != -1)
  return data[i].identity;
  }
  else if (dataProp)
  return data[i].identity;
  } 
  }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index + this.versionSearchString.length + 1)); }, dataBrowser: [{ string: navigator.userAgent, subString: "Chrome", identity: "Chrome" }, { string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "Version" }, { prop: window.opera, identity: "Opera" }, { string: navigator.vendor, subString: "iCab", identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror" }, { string: navigator.userAgent, subString: "Firefox", identity: "Firefox" }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" }, { string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" }, { string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla"}], dataOS: [{ string: navigator.platform, subString: "Win", identity: "Windows" }, { string: navigator.platform, subString: "Mac", identity: "Mac" }, { string: navigator.userAgent, subString: "iPhone", identity: "iPhone/iPod" }, { string: navigator.platform, subString: "Linux", identity: "Linux"}]
  }; BrowserDetect.init(); window.$.client = { os: BrowserDetect.OS, browser: BrowserDetect.browser, browserversion: BrowserDetect.version };
  })();




