var feedType="all";
var monthToDisplay='';
var currnetPageNumberAU=0;
var currnetPageNumberNZ=0;
var currnetPageNumber=0;
var achievementCurrnetPageNumber=0;

$(document).ready(function(){
    
    if($.browser.msie)
    {
        document.onfocusout = function(){blurMedia();}
        document.onfocusin = function(){focusMedia();}
    }
    else
    {
        $(window.top).blur(function(e){
            blurMedia();
        });
        
        $(window.top).focus(function(e){
            focusMedia();
        });
    }
    
    //giftcard hide show
    
    $("div.giftCardHidden").hide();
    $("a.gcPop").click(function(e){
           
    if ($(this).next('div').is(':hidden')) {
        $(this).next('div').slideDown('fast');
        e.preventDefault();     
    } else {        
       $(this).next('div').slideUp();
       e.preventDefault();    
    }
      
    });
    
    //Product Details Overlay stuff
    $('a.productFullOverlay').click(function(e){
        aTag = $(this);
        $(aTag.attr('rel') + " img").remove();
        $(aTag.attr('rel')).append("<img src='" + aTag.attr('href') + "' alt='" + aTag.attr('title') + "' />");
    });
  
       // avatarEditor stuff.
  
   
       $('a.creatAvatarProfile').click(function(e){
         
         expandCreator();
         e.preventDefault();        
         
       });
       
        $('a.editjayvatar').click(function(e){
         expandCreator();
         e.preventDefault();                 
       });
       
       $('a.playgroundPop').click(function(e){
         showPlayground();
         e.preventDefault();                
       });
       
       
       
       // product Carousel
       
        $('div.switchPanel a.nextProduct').click(function() {
            var visLi = $(this).parent('div').children('ul').children('li.visible');
            var nextLi = $(visLi).next();
            var lastLi = $(this).parent('div').children('ul').children('li:last');

            $(visLi).animate({ left: '-413' }, 200, function() {
                $(this).removeAttr('class');
                $(this).removeAttr('style');              
                $(this).insertAfter(lastLi);
                $(nextLi).addClass("rightOver");
                $(nextLi).animate({ left: '0' }, 400, function() {
                    $(nextLi).addClass('visible');            
                });
            });
        });
       
        $('div.switchPanel a.prevProduct').click(function() {
            var visLi = $(this).parent('div').children('ul').children('li.visible');
            var prevLi = $(this).parent('div').children('ul').children('li:last');

            $(visLi).animate({ left: '826' }, 200, function() {
                $(this).removeAttr('class');
                $(this).removeAttr('style');              
                $(prevLi).insertBefore($(this));
                $(prevLi).animate({ left: '0' }, 400, function() {
                    $(prevLi).addClass('visible');           
                }); 
            });
        });
      
      
      //product Carousel hide and show function
      
        $('div.headerWrap a.carouselSwitch').click(function(){
        
				$('div.visSwitch').removeClass("visSwitch");
				$('div.headerWrap a.carouselSwitch').removeClass('active');
         
        var showState = $(this).attr('rel');
    
        $('div.switchPanel').hide();
        $(showState).fadeIn();
        
        $(showState).addClass("visSwitch");
        $(this).addClass('active');
        
        return false;
            
      });
          
      
      //clear the iframe contents before re-loading
      
      $('a.iframePop').click(function(){
        var iframeSrc = $(this).attr('href');
        if(iframeSrc.indexOf('?') >= 0)
        {
            iframeSrc += "&js=1";
        }
        else
        {
            iframeSrc += "?js=1";
        }
        var iframeContent = '<iframe scrolling="no"></iframe>'         
        
        //alert(iframeSrc);
                
        $('div.simple_overlay iframe').remove();
        $('div.simple_overlay .close').after(iframeContent);
        $('div.simple_overlay iframe').attr('src', iframeSrc);

        
      });
      
      //clear Products popup before Load
      
      $('div.productDetailLeft a.popupLink').click(function(){       
        $('div#zoomIn iframe').remove();       
      });
  
      
      //active class for the jFeed section

      $('ul.filterNav a').click(function(){
        $('ul.filterNav a').removeAttr("class");
        $(this).addClass('active');     
      });
       
      //add activeInput class to submit buttons on hover 
      
      $('input.subRes').hover(function(){
        $(this).addClass('activeInput');
      },
      function (){
        $(this).removeClass('activeInput');
      }
      );
          
      //convert rel="external" to target blank on ck
      
      $('a[rel="external"]').click(function(){
		     this.target = "_blank";
	    });
         
      
   // clear field on click replace with default value on blur.
  
   $("input.postCodeSearch, input.productSearchTxt, input.searchText").focus(function() {
    
        this.value = "";
   
   }).blur(function() {
      if( !this.value.length ) {
          this.value = this.defaultValue;
      }
   })
  
  
  // hide and show, only used on the competitions winners page for now.
  
  $('div.winners').hide();
  $('a.openWinner').click(function(){
    
   if ($(this).next('div').is(':hidden')) {
       $(this).next('div').addClass('closeIt');
       $(this).addClass('closeLink');
       $(this).next('div').slideDown('fast');
    } else {     
       $(this).next('div').removeClass('closeIt');       
       $(this).next('div').slideUp();
       $(this).removeClass('closeLink');
    }
    
  });  
  
  // Store Locator Hide and Show + also Used for Charities Hide Show + jgear product switch
  
  $('div.storeWrapper div.left:not(:first)').hide();
  $('ul.storeState > li > a').click(function(){
    
    var showState = $(this).attr('rel');

    $('div.storeWrapper > div.left:visible').hide();
    $(showState).fadeIn();
    
    $('ul.storeState > li > a.active').removeClass("active");
    $(this).addClass("active");
    return false;
        
  });
 
   // nearest Stores hide and show
   
   $('div.nearestStoresList span.address:not(:first)').hide();
   $('div.nearestStoresList ul li a').click(function(){
          
     $('div.nearestStoresList span.address').hide();
     $(this).next('span').fadeIn();
     
     return false;
     
   }); 
   
   
   
   //-----------------------Jfeed---------------------------
   //Get feed only for home page and JFeed page
   if($(".feedWrapper").length>0)
   {
     GetFeedByCatagory();
   }
   NextClick();
   PreviousClick();
   LikeClick();
   MoreDateClick();
   ArchiveDateClick()
   ShowVideo();
   ModifyLinks();
   GetPopupLink();
   //overlayImg();
   
   $(".filterVid").click(function(e)
   {
        feedType ="video"
        currnetPageNumber=0;
        GetFeedByCatagory();
        e.preventDefault();
        
    });        
    
    $(".filterPic").click(function(e)
   {
        feedType="album";
        currnetPageNumber=0;
        GetFeedByCatagory();
        e.preventDefault();
    }); 
    
     $(".filterSho").click(function(e)
   {
        feedType = "shout"
        currnetPageNumber=0;
        GetFeedByCatagory();
        e.preventDefault();
    }); 
    
    $(".filterResetAll").click(function(e)
   {
        feedType ="all";
        currnetPageNumber=0;
        monthToDisplay='';
        GetFeedByCatagory();
        $('.archiveList li a').removeClass('active');
        e.preventDefault();
    }); 
    
    $(".filterMostLiked").click(function(e)
   {
        feedType ="mostLiked";
        currnetPageNumber=0;
        GetFeedByCatagory();
        e.preventDefault();
    });

// -------------------------  Charity Feed ---------------------

  FeedPreviousClick(); 
  FeedNextClick();
  ChangeContentLink();
  AddDisabledClass();
  overlayImg();

//---------------------------- Your Profile  -------------------------------------
   
        //  --- Profile Jfeed Liked ----
           
    ProfileFeedPreviousClick();
    ProfileFeedNextClick();
    DeleteProfileLikedFeed();
    AddDisabledClass();

    //  --- Profile Achievements ----
    ProfileAchievementPreviousClick();
    ProfileAchievementNextClick();
   
});
//End $(document).ready()

function AddDisabledClass()
{  
    $('.charityFeedWrapper a[disabled="disabled"]').addClass("disabled");
    $('.stuffYouLikes a[disabled="disabled"]').addClass("disabled");
    $('.yoursAcheivments a[disabled="disabled"]').addClass("disabled");
    
}

//-----------------------Jfeed---------------------------
function GetPopupLink()
{     
    
$("li.feedTypeAlbum a img").each(function(){
  $(this).parent('a').attr('href', $(this).attr('src').replace(/_s.jpg/i, "_n.jpg"));  
  $(this).parent('a').addClass("popupLink");
});
   
}   

 
function overlayImg() { 
  
  $("li.feedTypeAlbum").each(function() { 
    $("a.popupLink",this).overlay({   
      target: '#gallery',   
      expose: '#000'  
    }).gallery({speed:800, template: '<span>Image ${index} of ${total}</span>'}); 
  }); 
  
    
}

function ModifyLinks()
{

//$(".feedWrapper .contentWrapper a").removeAttr("href");
  $(".feedWrapper .contentWrapper a").each(function(){ 
     $(this).attr('target',"_blank");
      if(location.href.match("/jfeed.aspx"))
      {        
         $(this).attr("onclick","setGlobalTracking('JayJays_JFeed',  'Feed_Content_Click','" + $(".externalLink").attr("href") + "')");
      }
      else
      {
        $(this).attr("onclick","setGlobalTracking('JayJays_Home',  'Jfeed_interact_click','" + $(".externalLink").attr("href") + "')");
      }
});
$(".postedLikeWraper .like").each(function(){
    if(location.href.match("/jfeed.aspx"))
      {        
         $(this).attr("onclick","setGlobalTracking('JayJays_JFeed',  'Like_Click','" + $(".externalLink").attr("href") + "')");
      }
      else
      {
        $(this).attr("onclick","setGlobalTracking('JayJays_Home',  'Jfeed_like','" + $(".externalLink").attr("href") + "')");
      }
});

}


function ShowVideo()
{
   //Replace image with video
   $(".feedTypeVideo .contentWrapper a").click(function(e)
   {
        if($(this).parent($(".contentWrapper")).children($("a:first")).children("img").length > 0)
        {
            $(this).parent($(".contentWrapper")).children($("a:first")).children("img").replaceWith($(this).parent($(".contentWrapper")).children($(".videoWrapper")).html());
        }
        e.preventDefault();
   });
}

function GetFeedByCatagory()
{
	
	var param = "feedType=" + feedType + "&currnetPageNumber=" + currnetPageNumber + "&monthToDisplay=" + monthToDisplay	;
	$.ajax({
    type: "POST",
    url: "/ajax/ajaxJFeed.aspx",
    data: param,
    success: function(text) { 
        $(".feedWrapper").animate({opacity:0}, 150, function() {
        $(".feedWrapper").css('display', 'block');
        $(".feedWrapper").html(text).animate({opacity:1}, 150);
        $(".feedWrapper").html(text);
        $('.feedWrapper a[disabled="disabled"]').addClass("disabled");
        NextClick();
        PreviousClick();
        LikeClick();
        ShowVideo();
        ModifyLinks();
        GetPopupLink();
        overlayImg();
        }); 
    }
    });
}


function PreviousClick() 
{
   $(".feedWrapper .newerPosts").click(function(e)
   {
        currnetPageNumber =$(".feedWrapper .newerPosts").attr("rel");
        if(currnetPageNumber != "-1")
        {
            GetFeedByCatagory();
        }
   });
}

function NextClick()
{
   $(".feedWrapper .olderPosts").click(function(e)
   {
            
        currnetPageNumber =$(".feedWrapper .olderPosts").attr("rel");
        if(currnetPageNumber != "-1")
        {
            GetFeedByCatagory();
        }
   });
}

function LikeClick()
{
   $(".like").click(function(e)
   {
     if($(this).attr("class") != "like disabled" )
	      {
   
        $(this).addClass("disabled");
        var feedID = $(this).prev($("[id$='hdnFeedID']")).val();
        
        var param = "feedID=" + feedID ;
        var obj =$(this);
	    $.ajax({
        type: "POST",
        url: "/ajax/ajaxFeedLike.aspx",
        data: param,
        success: function(txt) { 
            obj.text("Like (" + txt + ")");
            obj.attr("class","like disabled");
        }
        });
      }
      e.preventDefault();
   });
}

 function MoreDateClick()
 {
     $(".more").unbind();
     $(".more").click(function(e)
     {
	    var dateID= $(this).prev("li").attr("rel");
	    var param = "dateID=" + dateID;
	    $.ajax({
        type: "POST",
        url: "/ajax/ajaxFeedArchive.aspx",
        data: param,
        success: function(text) { 
           $(".more").animate({opacity:0}, 150, function() {
           $(".more").css('display', 'block');
           $(".more").replaceWith(text).animate({opacity:1}, 150);
           MoreDateClick();
           ArchiveDateClick();
           }); 
        }
        });
        e.preventDefault();
    });
}

function ArchiveDateClick()
 {
    $(".archiveList li").unbind();
    MoreDateClick();
     $(".archiveList li").click(function(e)
     {
	    if($(this).attr("class") != "more" )
	    {
	        feedType ="all"
            currnetPageNumber=0;
            monthToDisplay = $(this).children($("a")).html();
//                if(monthToDisplay.replace(/^\s+|\s+$/g, '') == "Current")
//                {
//                    monthToDisplay='';
//                    $('.latestUpdates').text('LATEST UPDATES');
//                }
//                else
//                {
//                    $('.latestUpdates').text($(this).text() + ' UPDATES');
//                }
            $('.latestUpdates').text($(this).text() + ' UPDATES');
            $('ul.filterNav li a').removeClass('active');
            $('.archiveList li a').removeClass('active');
            $(this).children($('a')).addClass('active');
            Cufon.refresh();
            GetFeedByCatagory();
        }
        e.preventDefault();
        
    });
}

// -------------------------  Charity Feed ---------------------


function exposeFix() {
  
  winheight = $(document).height();
  $('body div:last').css('height', winheight);
 
}



function clearIframe(){
 $('a.iframePop').click(function(){
   var iframeSrc = $(this).attr('href');
   if (iframeSrc.indexOf('?') >= 0) {
     iframeSrc += "&js=1";
   }
   else {
     iframeSrc += "?js=1";
   }
   var iframeContent = '<iframe scrolling="no"></iframe>'
   
   //alert(iframeSrc);
  
  $('div.simple_overlay iframe').remove();
  $('div.simple_overlay .close').after(iframeContent);
  $('div.simple_overlay iframe').attr('src', iframeSrc);
  
});
}  
 
function GetAUCharityFeed()
{
	
	var param = "currnetPageNumber=" + currnetPageNumberAU + "&currentCharityCountry=AU" ;
	$.ajax({
        type: "POST",
        url: "/ajax/ajaxCharityFeed.aspx",
        data: param,
        success: function(text) { 
            $(".charityFeedWrapper").animate({opacity:0}, 150, function() {
                $(".charityFeedWrapper").css('display', 'block');
                $(".charityFeedWrapper").html(text);
                AddDisabledClass();
                FeedNextClick();
                FeedPreviousClick();
                ChangeContentLink();
                $("a.popupLink[rel]").overlay({expose: '#000'});                                 
                clearIframe();
                exposeFix()
                Cufon.replace('.cufon');
                $(".charityFeedWrapper").animate({opacity:1}, 150);
            }); 
        }
    });
}

 function GetNZCharityFeed()
{
	var param = "currnetPageNumber=" + currnetPageNumberNZ + "&currentCharityCountry=NZ" ;
	$.ajax({
        type: "POST",
        url: "/ajax/ajaxCharityFeed.aspx",
        data: param,
        success: function(text) { 
            $(".charityFeedWrapper").animate({opacity:0}, 150, function() {
                $(".charityFeedWrapper").css('display', 'block');
                $(".charityFeedWrapper").html(text);
                AddDisabledClass();
                FeedNextClick();
                FeedPreviousClick();
                $("a.popupLink[rel]").overlay({expose: '#000'}); 
                clearIframe();
                exposeFix()
                Cufon.replace('.cufon');
                $(".charityFeedWrapper").animate({opacity:1}, 150);
            }); 
        }
    });
}

  function GetSACharityFeed()
{
	var param = "currnetPageNumber=0&currentCharityCountry=SA" ;
	$.ajax({
        type: "POST",
        url: "/ajax/ajaxCharityFeed.aspx",
        data: param,
        success: function(text) { 
            $(".charityFeedWrapper").animate({opacity:0}, 150, function() {
                $(".charityFeedWrapper").css('display', 'block');
                $(".charityFeedWrapper").html(text);
                AddDisabledClass();
                $("a.popupLink[rel]").overlay({expose: '#000'});     
                clearIframe();
                exposeFix()
                Cufon.replace('.cufon');
                $(".charityFeedWrapper").animate({opacity:1}, 150);
            });
        }
    });
}

function FeedPreviousClick() 
{
   $(".charityFeedWrapper .charityContentAU .newerPosts").click(function(e)
   {
        currnetPageNumberAU =$(".charityFeedWrapper .charityContentAU .newerPosts").attr("rel");
        if(currnetPageNumberAU != "-1")
        {
            GetAUCharityFeed();
        }
   });
   
     $(".charityFeedWrapper .charityContentNZ .newerPosts").click(function(e)
   {
        currnetPageNumberNZ =$(".charityFeedWrapper .charityContentNZ .newerPosts").attr("rel");
        if(currnetPageNumberNZ != "-1")
        {
            GetNZCharityFeed();
        }
   });
}

function FeedNextClick()
{
   $(".charityFeedWrapper .charityContentAU .olderPosts").click(function(e)
   {
            
        currnetPageNumberAU =$(".charityFeedWrapper .charityContentAU .olderPosts").attr("rel");
        if(currnetPageNumberAU != "-1")
        {
            GetAUCharityFeed();
        }
   });
   
   $(".charityFeedWrapper .charityContentNZ .olderPosts").click(function(e)
   {
            
        currnetPageNumberNZ =$(".charityFeedWrapper .charityContentNZ .olderPosts").attr("rel");
        if(currnetPageNumberNZ != "-1")
        {
            GetNZCharityFeed();
        }
   });
}

function ChangeContentLink()
{     
    
$(".charityFeedWrapper .charityContentAU .contentWrapper a").each(function(){
  //alert($(this).attr('href');
  $(this).attr('href', $(this).attr('href').replace("../../", "http://au.reachout.com/"));  
  $(this).attr('target',"_blank");
});
   
}

//---------------------------- Your Profile  -------------------------------------
   
        //  --- Profile Jfeed Liked ----

function ProfileFeedPreviousClick() 
{
   $(".stuffYouLikes .prev").click(function(e)
   {
        currnetPageNumber =$(".stuffYouLikes .prev").attr("rel");
        if(currnetPageNumber != "-1")
        {
            GetProfileLikedFeed();
        }
   });
}

function ProfileFeedNextClick()
{
   $(".stuffYouLikes .next").click(function(e)
   {
        currnetPageNumber =$(".stuffYouLikes .next").attr("rel");
        if(currnetPageNumber != "-1")
        {
            GetProfileLikedFeed();
        }
   });
}

function GetProfileLikedFeed()
{
	
	var param = "currnetPageNumber=" + currnetPageNumber ;
	$.ajax({
    type: "POST",
    url: "/ajax/ajaxProfileLikedFeed.aspx",
    data: param,
    success: function(text) { 
        $(".stuffYouLikes").animate({opacity:0}, 150, function() {
        $(".stuffYouLikes").css('display', 'block');
        $(".stuffYouLikes").html(text).animate({opacity:1}, 150);
        $(".stuffYouLikes").html(text);
        ProfileFeedNextClick();
        ProfileFeedPreviousClick();
        ShowVideo();
        ModifyLinks();
        GetPopupLink();
        overlayImg();
        DeleteProfileLikedFeed();
        AddDisabledClass();
        }); 
    }
    });
}

function DeleteProfileLikedFeed()
{
	$(".stuffYouLikes .remove").click(function(e)
	{
	    var id = $(this).prev($(".hdnMemberFeedID")).val();
	    var param = "currnetPageNumber=" + currnetPageNumber  +"&id=" + id;
	    $.ajax({
        type: "POST",
        url: "/ajax/ajaxDeleteProfileLikedFeed.aspx",
        data: param,
        success: function(text) { 
            $(".stuffYouLikes").animate({opacity:0}, 150, function() {
            $(".stuffYouLikes").css('display', 'block');
            $(".stuffYouLikes").html(text).animate({opacity:1}, 150);
            $(".stuffYouLikes").html(text);
            ProfileFeedNextClick();
            ProfileFeedPreviousClick();
            ShowVideo();
            ModifyLinks();
            GetPopupLink();
            overlayImg();
            AddDisabledClass();
            DeleteProfileLikedFeed();
            }); 
        }
        });
        e.preventDefault();
    });    
}

    //  --- Profile Achievements ----
function ProfileAchievementPreviousClick() 
{
   $(".yoursAcheivments .prev").click(function(e)
   {
        achievementCurrnetPageNumber =$(".yoursAcheivments .prev").attr("rel");
        if(achievementCurrnetPageNumber != "-1")
        {
            GetProfileAchievement();
        }
   });
}

function ProfileAchievementNextClick()
{
   $(".yoursAcheivments .next").click(function(e)
   {
        achievementCurrnetPageNumber =$(".yoursAcheivments .next").attr("rel");
        if(achievementCurrnetPageNumber != "-1")
        {
            GetProfileAchievement();
        }
   });
}

function GetProfileAchievement()
{
	
	var param = "currnetPageNumber=" + achievementCurrnetPageNumber ;
	$.ajax({
    type: "POST",
    url: "/ajax/ajaxProfileAchievement.aspx",
    data: param,
    success: function(text) { 
        $(".yoursAcheivments").animate({opacity:0}, 150, function() {
        $(".yoursAcheivments").css('display', 'block');
        $(".yoursAcheivments").html(text).animate({opacity:1}, 150);
        $(".yoursAcheivments").html(text);
        ProfileAchievementNextClick();
        ProfileAchievementPreviousClick();
        AddDisabledClass();
        }); 
    }
    });
}

function SearchStore(val)
{ 
    
    if(val != undefined && val != "" && val != "Postcode")
    {
        location.href = "/storelocator.aspx?Postcode=" + val; 
    } 
    else
    {
        return false;
    }
}


function WebForm_FireDefaultButton(event, target) {
var __defaultFired = false;
var __nonMSDOMBrowser = 
    window.navigator.appName.toLowerCase()
    if (!__defaultFired && event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
        var defaultButton;
        if (__nonMSDOMBrowser) {
            defaultButton = document.getElementById(target);
        }
        else {
            defaultButton = document.all[target];
        }
        if (defaultButton && typeof(defaultButton.click) != "undefined") {
            __defaultFired = true;
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}

function getFlashVersion(){ 
  // ie 
  try { 
    try { 
      // avoid fp6 minor version lookup issues 
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
      try { axo.AllowScriptAccess = 'always'; } 
      catch(e) { return '6,0,0'; } 
    } catch(e) {} 
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
  // other browsers 
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
      } 
    } catch(e) {} 
  } 
  return '0,0,0'; 
}


// slide in the avatar creatorrrrrrrrrr ha ha ha ..

    function expandCreator()
    {
        $.ajax({
            url: "/ajax/ajaxAvatarCreator.aspx",
            success: function(data){
                $("#avatarEditorFlash").empty();
                $("#avatarEditorFlash").html(data);
                $('html, body').animate({scrollTop:0}, "slow");
                $('div.avatarEditor').animate({height: "600"}, "slow");
                $('div.paperLine').animate({top: "1065"}, "slow");
                disableLogin();
                pause();
            }
        });
    }
  
    function closeCreator()
    {
        //alert("close creator");
        $('div.paperLine').animate({top: "465"}, "500");
        $('div.avatarEditor').animate({height: "0"}, "500", function(){
            $("#avatarEditorFlash").empty();
            refresh();
            enableLogin();
            resume();
            if($(".avatarContainer").size() > 0)
            {
                window.top.location.href = window.top.location.href;
            }
        });
    } 
	
    function pause() {
			//alert("pause: " + document.getElementById('core'));
			try
			{
			    document.getElementById('core').pauseMediaPanel();
			}
			catch(e)
			{
			}
		}
		
		function resume() {
			//alert("resume: " + document.getElementById('core'));
			try
			{
			    document.getElementById('core').resumeMediaPanel();
			}
			catch(e)
			{
			}
		}
    
    function refresh() {
      //alert("refreshing")
			try
			{
			    document.getElementById('core').refreshLogin();
			}
			catch(e)
			{
			}
		}		
		
		function disableLogin() {
      //alert("disabling")
			try
			{
			    document.getElementById('core').disableLogin();
			}
			catch(e)
			{
			}
		}
		
		function enableLogin() {
      //alert("enabling")
			try
			{
			    document.getElementById('core').enableLogin();
			}
			catch(e)
			{
			}
		}		

		function returnToSite() {
			//alert("Return to site");
            try
            {
			    closeCreator();
			}
			catch(e)
			{
			}
		}
		
		function blurMedia() {
			try
			{
			    //$("#testpara").remove();
			    //$("body").prepend("<p id='testpara'>Blur!</p>")
			    document.getElementById('core').blurMedia();
			}
			catch(e)
			{
			}
		}
		
		function focusMedia() {
			try
			{
			    //$("#testpara").remove();
			    document.getElementById('core').focusMedia();
			}
			catch(e)
			{
			}
		}
		
		function showPlayground()
		{
		    setGlobalTracking('Play', 'Visit_Playground_Click', window.location.href);
			popup('/playground.aspx', 'playground', 960, screen.height, 0, 0, 0);
		}
   
   /* Analytics tracking */
   
   function getCountry()
   {
        var country = "AU"
        if(location.href.match(".com.nz"))
        {
                country = "NZ"
        }   
        else if(location.href.match(".co.za"))
        {
                country = "SA"
        }   
        
        return country;
   }
   
   function setTrackingData(val,category,option1) 
   {
        setGlobalTracking(val,category,$(option1).html());
   }
   
   function setGlobalTracking(val,category,option1)
   {    
     
     if(option1 != undefined)
     {  
        //alert(val + '_' + getCountry() + " " + category + " " + option1);
        pageTracker._trackEvent(val + '_' + getCountry(),category,option1);
     }
     else
     { 
        //alert(val + '_' + getCountry() + " " + category);
        pageTracker._trackEvent(val + '_' + getCountry(),category);
     }
   } 
   
   function findAllAnchor(val)
   { 
        if($(val) != undefined && $(val).attr("href") != undefined && ! $(val).html().match("Read More"))
        {     
            if($(val).attr("href").match("http://")|| $(val).attr("href").match("https://") ||  $(val).attr("href").match("mailto:"))
            {
                $(val).attr("onclick","setGlobalTracking('Outbound_link_click','" + $(val).attr("href") + "')");
            }
        }
                 
   }
   
   function alphanumeric_only(e)
    {
        var keycode = 0;
        e= (window.event)? event : e;
	    keycode = (e.keyCode)? e.keyCode: e.charCode;
	    
        if( keycode ==8 || keycode ==9 ||  (keycode >= 47 && keycode <= 57) || (keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122) )
        {
            return true;
        }
        else
        {
            return false;
        }
        return true;
   } 