function getURL_of_Publication()
{
    var hostName = window.location.host;
   if(hostName.indexOf("ece-dev2")!=-1 || hostName.indexOf("test.escenic")!=-1 || hostName.indexOf("migrate")!=-1)
        return window.location.protocol + "//" + window.location.host + '/timeslive';
    else
        return window.location.protocol + "//" + window.location.host;
}

var publicationURL = getURL_of_Publication();

/* Fancy forms */
$(function(){
    $("#docs h5 a").click(function(){
        var a=$(this).attr("href");
        $(a).slideToggle();
        return false
        });
    $(".parameter").hide();
    $("select, input[type='checkbox'], input[type='radio'], input[type='file']").uniform();
    $("a.btn[rel='disable']").live("click",function(){
        $("select, input[type='checkbox'], input[type='radio'], input[type='file']").attr("disabled",true);
        $.uniform.update();
        $(this).attr("rel","enable").text("Enable All");
        return false
        });
    $("a.btn[rel='enable']").live("click",function(){
        $("select, input[type='checkbox'], input[type='radio'], input[type='file']").removeAttr("disabled");
        $.uniform.update();
        $(this).attr("rel","disable").text("Disable All");
        return false
        });
    $("a.btn[rel='reset']").click(function(){
        $("form").get(0).reset();
        $.uniform.update();
        return false
        });
});


/* Tab Switching */
$(function() {
    $(".tabMenu").each(function(B,D) {
        var A=$(D).children("li");
        var C=$(D).nextAll(".tabContent");
        var eventtype="click";
		 
        if(A.length==0) {
            return
        }
        if(A.length!=C.length) {
            return
        }
        A.each(function(F,E)
        {
            C.eq(F)[$(E).hasClass("selected")?"show":"hide"]();
            if($(E).hasClass("ht"))
            {
                $(E).find("a").hover(function(G)
                {
                    A.removeClass("selected").eq(F).addClass("selected");
                    G.preventDefault();
                    C.hide();
                    C.eq(F).show();
                    return false
                })
            }
            else
            {
				
				
                $(E).find("a").click(function(G)
                {
                    A.removeClass("selected").eq(F).addClass("selected");
                    G.preventDefault();
                    C.hide();
                    C.eq(F).show();
                    return false
                })
				
				
            }
			

        }
        )
    }
    )
}
);

 

jQuery.fn.accessNews = function( settings ) {
    settings = jQuery.extend({
        headline : "Top Stories",
        speed : "normal",
        slideBy : 2
    }, settings);
    return this.each(function() {
        jQuery.fn.accessNews.run( jQuery( this ), settings );
    });
};
jQuery.fn.accessNews.run = function( $this, settings ) {
    jQuery( ".javascript_css", $this ).css( "display", "none" );
    var ul = jQuery( "ul:eq(0)", $this );
    var li = ul.children();
    if ( li.length > settings.slideBy ) {
        var $next = jQuery( ".next > a", $this );
        var $back = jQuery( ".back > a", $this );
        var liWidth = jQuery( li[0] ).width();
        var animating = false;
        ul.css( "width", ( li.length * liWidth ) );
        $next.click(function() {
            if ( !animating ) {
                animating = true;
                offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
                if ( offsetLeft + ul.width() > 0 ) {
                    $back.css( "display", "block" );
                    ul.animate({
                        left: offsetLeft
                    }, settings.speed, function() {
                        if ( parseInt( ul.css( "left" ) ) + ul.width() <= liWidth * settings.slideBy ) {
                            $next.css( "display", "none" );
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
        $back.click(function() {
            if ( !animating ) {
                animating = true;
                offsetRight = parseInt( ul.css( "left" ) ) + ( liWidth * settings.slideBy );
                if ( offsetRight + ul.width() <= ul.width() ) {
                    $next.css( "display", "block" );
                    ul.animate({
                        left: offsetRight
                    }, settings.speed, function() {
                        if ( parseInt( ul.css( "left" ) ) == 0 ) {
                            $back.css( "display", "none" );
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
        $next.css( "display", "block" )
        .parent().after( [ "" ].join( "" ) );
        jQuery( ".view_all > a, .skip_to_news > a", $this ).click(function() {
            var skip_to_news = ( jQuery( this ).html() == "Skip to News" );
            if ( jQuery( this ).html() == "view all" || skip_to_news ) {
                ul.css( "width", "auto" ).css( "left", "0" );
                $next.css( "display", "none" );
                $back.css( "display", "none" );
                if ( !skip_to_news ) {
                    jQuery( this ).html( "view less" );
                }
            } else {
                if ( !skip_to_news ) {
                    jQuery( this ).html( "view all" );
                }
                ul.css( "width", ( li.length * liWidth ) );
                $next.css( "display", "block" );
            }
            return false;
        });
    }
};


// Top na Drop down menu
var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

function mopen(id)
{	
	
    mcancelclosetime();


    if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';


    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.visibility = 'visible';

}

function mclose()
{
    if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}


function mclosetime()
{
    closetimer = window.setTimeout(mclose, timeout);
}


function mcancelclosetime()
{
    if(closetimer)
    {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

// close layer when click-out
document.onclick = mclose; 


$(document).ready(function () {

    $('.float-banner div').floatingbanner();
});




$(document).ready(function(){
    //To switch directions up/down and left/right just place a "-" in front of the top/left attribute
    //Vertical Sliding
    $('.boxgrid.slidedown').hover(function(){
        $(".cover", this).stop().animate({
            top:'70px'
        },{
            queue:false,
            duration:300
        });
    }, function() {
        $(".cover", this).stop().animate({
            top:'260px'
        },{
            queue:false,
            duration:300
        });
    });
});
			
			
			
			
			
$(document).ready(function()
{
    $(".signin").click(function(e)
    {
        e.preventDefault();
        $("div#signin_menu").toggle();
        $(".signin").toggleClass("menu-open");
        document.getElementById("signin_menu").style.left = e.pageX - 310 +"px";
        document.getElementById("signin_menu").style.top = e.pageY + 10 +"px";
        document.getElementById("signin_menu").style.zIndex = 10000;
    });

    $(".signin2").click(function(e)
    {
        e.preventDefault();
        $("div#signin_menu").toggle();
        $(".signin2").toggleClass("menu-open");
        document.getElementById("signin_menu").style.left = e.pageX -10 +"px";
        document.getElementById("signin_menu").style.top = e.pageY + 10 +"px";
        document.getElementById("signin_menu").style.zIndex = 10000;
    });

    $("div#signin_menu").mouseup(function()
    {
        return false
    });
	
    $(document).mouseup(function(e)
    {
        /*$("#log").html("clicked: " + e.target.nodeName);*/
        if($(e.target).parent("a.signin").length==0 && $(e.target).parent("a.signin2").length==0)
        {
            //alert("in here");
            $("div#signin_menu");
            $(".signin").removeClass("menu-open");
            $("div#signin_menu").hide();
        }
    });
});


/* Flash multimedia scripts*/
//Flash functions
function changeFlash(vidid, vidext, vidtype, contentHolder, vidheight, vidwidth, articleTitle)
{
    //alert("http://multimedia.avusa.co.za/" + vidtype + "/" + vidid + vidext);
    var defaultImage = "";
    var flashvars;

    if (vidext == ".mp3")
    {
        defaultImage = "http://multimedia.timeslive.co.za/thumbs/imgcache/630x354-"+vidid+".jpg";
    }
    else
    {
        defaultImage = "http://multimedia.timeslive.co.za/thumbs/imgcache/630x354-"+vidid+".jpg";
    }

    if (vidext == '.mp3')
		{
    		flashvars = {
    	        height:vidheight,
    	        width:vidwidth,
    	        file:"http://multimedia.timeslive.co.za/" + vidtype + "/" + vidid + vidext,
    	        skin:publicationURL + "/player/skins/modieus_slim/timeslivea54.swf",
    	        image:defaultImage,
    	        plugins: "googima,gapro-1",
    	        'gapro.trackstarts': true,
    	        'gapro.trackpercentage':true,
    	        'gapro.idstring':"(||"+ vidid + "||-||" + articleTitle + "||)",
    	        'gapro.accountid':"UA-9714899-1",
    	        'bufferlength':5   
    		};
    	        
		}
    else
    	{
    		flashvars = {
    	        height:vidheight,
    	        width:vidwidth,
    	        file:"http://multimedia.timeslive.co.za/" + vidtype + "/" + vidid + vidext,
    	        skin:publicationURL + "/player/skins/modieus_slim/timeslivea54.swf",
    	        image:defaultImage,
    	        plugins: "googima,gapro-1",
    	        'gapro.trackstarts': true,
    	        'gapro.trackpercentage':true,
    	        'gapro.idstring':"(||"+ vidid + "||-||" + articleTitle + "||)",
    	        'gapro.accountid':"UA-9714899-1",
    	        'googima.ad.tag': "http://ad.za.doubleclick.net/pfadx/timeslive2/VideoPlayer;sz=1x1000;tile=1;dcmt=text/xml;ord=1234567890?",
    	        'googima.ad.position': "pre",
    	        'googima.scaled_ads': true,
    	        'bufferlength':5,             
    	        'provider':'http'
    		};
    	
    	}
    

    var params = {
        allowfullscreen: "true",
        wmode: "transparent",
        allowScriptAccess: "always"
    };

    var attributes = {};

    swfobject.embedSWF(publicationURL + "/player/player.swf", contentHolder, vidwidth, vidheight, "8","", flashvars, params, attributes);
}

//Flash functions
function changeFlashLarge(vidid, vidext, vidtype, contentHolder, articleTitle)
{
    //alert(vidid);
    var defaultImage = "";
    var flashvars;
    
    if (vidext == ".mp3")
    {
        defaultImage = "http://multimedia.avusa.co.za/images/psd-AVUSA-podcast.jpg";
    }
    else
    {
        defaultImage = "http://multimedia.avusa.co.za/thumb/1_" + vidid + "_overlay.jpg";
    }

    if (vidext == '.mp3')
    	{
    		flashvars = {
    	        height:"463",
    	        width:"630",
    	        file:"http://multimedia.avusa.co.za/" + vidtype + "/" + vidid + vidext,
    	        skin:publicationURL + "/player/skins/businesslive/blskin.swf",
    	        image:defaultImage,
    	        plugins: "googima,gapro-1",
    	        'gapro.trackstarts': true,
    	        'gapro.trackpercentage':true,
    	        'gapro.idstring':"(||"+ vidid + "||-||" + articleTitle + "||)",
    	        'gapro.accountid':"UA-9714899-1",
    	        'bufferlength':5
    	    };
    	
    	}
    else
    	{
    		flashvars = {
    	        height:"463",
    	        width:"630",
    	        file:"http://multimedia.avusa.co.za/" + vidtype + "/" + vidid + vidext,
    	        skin:publicationURL + "/player/skins/businesslive/blskin.swf",
    	        image:defaultImage,
    	        plugins: "googima,gapro-1",
    	        'gapro.trackstarts': true,
    	        'gapro.trackpercentage':true,
    	        'gapro.idstring':"(||"+ vidid + "||-||" + articleTitle + "||)",
    	        'gapro.accountid':"UA-9714899-1",
    	        'googima.ad.tag': "http://ad.za.doubleclick.net/pfadx/timeslive2/VideoPlayer;sz=1x1000;tile=1;dcmt=text/xml;ord=1234567890?",
    	        'googima.ad.position': "pre",
    	        'googima.scaled_ads': true,
    	        'bufferlength':5,             
    	        'provider':'http'
    	    };
    	
    	}
    
    	

    var params = {
        allowfullscreen: "true",
        wmode: "transparent",
        allowScriptAccess: "always"
    };

    var attributes = {};

    swfobject.embedSWF(publicationURL + "/player/player.swf", contentHolder, "610", "443", "8","", flashvars, params, attributes);
}

function goToJob()
{
    var jobAdNo = $.trim($('#jobNoInput').val());

    if(jobAdNo.length > 0)
    {
        var jobCode;

        jobAdNo = jobAdNo.toUpperCase();

        if(jobAdNo.indexOf("CJ")==0)
            jobCode = jobAdNo.split("J")[1];
        else
            jobCode = jobAdNo;

        window.location.href = '?filter=carjun&adNo='+jobCode;
    }

}

function setLaunchCookie()
{
    setPopupCookie("timesliveLaunch", "nevershow", 100);
}

function getPopupCookie(c_name)
{
    if (document.cookie.length > 0)
    {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setPopupCookie(c_name,value,exdays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function gotToJobCJ(jobAdNo)
{
    var cjHref = 'http://www.careerjunction.co.za/car/job/appfrm.asp?adno='+jobAdNo;
    window.open(cjHref,'cjWindow','width=800,height=640,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
}

