// This file should be compressed to ui.min.js using the YUI-Compressor with the syntax:
// java -jar c:\utility\yuicompressor-2.4.2\build\yuicompressor-2.4.2.jar ui.js -o ui.min.js
//
// http://developer.yahoo.com/yui/compressor/

var currentTabTimeout;

$(function() {
    $("#searchtext").watermark("Search this site");
    
    $("#nav > ul > li:has(div.callout)")
        .mouseenter(function() {
            $("#nav > ul > li").removeClass("selected");
            $(this).addClass("selected");
        });

    $("#nav > ul > li:has(div.callout) > a")
        .focus(function() {
            $("#nav > ul > li").removeClass("selected");
            $(this).parent("li").addClass("selected");
        });
    
    $("table.zebra tr:even").addClass("even");	
});

$(function() {
    $("#contentbase #content a#showall").click(
        function() {
            if ($("#contentbase #content a#showall").text()=='Show all')
            {			
                $("#contentbase #content dd, #contentbase #fullcontent dd").show();
                $("#contentbase #content a#showall").text("Hide all");		
            }
            else
            {
            $("#contentbase #content dd, #contentbase #fullcontent dd").hide();
            $("#contentbase #content a#showall").text("Show all");		
            }
        }
        );

    $("#contentbase #content dd, #contentbase #fullcontent dd").toggle(false);
    
    if (location.hash && location.hash!="#") $(location.hash).next("dd").show();		
});


$("#contentbase #content dt,#contentbase #fullcontent dt").click(function() {
    $(this).next("dd").slideToggle(100);
});

$("a.video").click(function(e) {

	t=0;
	hr=$(this).attr("href");	
	vid = hr.substr(hr.lastIndexOf("/")+1);	
	tp=vid.lastIndexOf("#t=");
	
	if (tp>-1) {
		t = parseInt(vid.slice(tp+3, -1));
		vid = vid.slice(0, tp);
	}
	
	$("div#modal div.dialog div.close").unbind('click');
	$("div#modal div.dialog").css("width", "642px");
	$("div#modal div.dialog").css("padding-left", "2px");
	$("div#modal div.dialog").unbind('click');	
	$("div#modal div.dialog").html('<div><iframe width="640" height="390" src="http://www.youtube.com/embed/' + vid + '?rel=0' + (t>0 ? '&start=' + t : '') + '" frameborder="0" allowfullscreen></iframe></div><div class="close"><a href="#" title="Close this dialog">close</a></div>');
	$("div#modal div.dialog div.close").show();
	$("div#modal div.dialog div.close").click(function () { ModalDialog.close(); $("div#modal div.dialog").html(''); if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } });
	
    ModalDialog.show("modal", false);
    ModalDialog.resize();

	e.preventDefault();
});

$(function() {
	
	$("a#quick_premium_increases").click(function() {
		woopraTracker.pushEvent({name:'quick answers',link:'2011 premium increases'});
	});
	
	$("a#quick_average_dental").live('click', function() {
		woopraTracker.pushEvent({name:'quick answers',link:'Average dental'});
	});

	$("a#quick_lhc_loading").click(function() {
		woopraTracker.pushEvent({name:'quick answers',link:'LHC loading'});
	});

	$("a#quick_457_visa").click(function() {
		woopraTracker.pushEvent({name:'quick answers',link:'457 visa'});
	});

	$("a#quick_ovhc").click(function() {
		woopraTracker.pushEvent({name:'quick answers',link:'Overseas visitors'});
	});

	$("a#quick_rebate").click(function() {
		woopraTracker.pushEvent({name:'quick answers',link:'Rebate'});
	});

	$("a#quick_faq").click(function() {
		woopraTracker.pushEvent({name:'quick answers',link:'FAQ'});
	});
	
	$("tr.other td.othergeneral a").click(function() {
		var id = $(this).attr("id").substring(13);
		woopraTracker.pushEvent({name:'Compare',link:'other features - general', id:id});
	});
	
	$("tr td.preferredprovider a").click(function() {
		var id = $(this).attr("id").substring(18);
		woopraTracker.pushEvent({name:'Compare',link:'preferred provider', id:id});
	});
	
	$("tr.other td.otherhospital a").click(function() {
		var id = $(this).attr("id").substring(14);
		woopraTracker.pushEvent({name:'Compare',link:'other features - hospital', id:id});
	});

	$("#comparisonTable table.comparison #tab_benefits").click(function() {
		woopraTracker.pushEvent({name:'Compare',link:'Benefits tab'});
    });

    $("#comparisonTable table.comparison #tab_limits").click(function() {
		woopraTracker.pushEvent({name:'Compare',link:'Limits tab'});
    });

});

$(function () {
    var cookies = document.cookie;
    var i = cookies.indexOf("loadmessage=");

    // change these to get a different message
    var title = "PrivateHealth.gov.au - Notice";
    var subTitle = "SIS regeneration underway";
    var message = "Please note that Standard Information Statements (SIS) are in the process of being updated to show information as at 1 April, 2011. Statements printed out today may not contain the latest information.";

    var showMessage = false;

    if (i != -1) {
        var s = i + 12;
        var e = cookies.indexOf(";", s);
        if (e == -1) e = cookies.length;

        var oldmessage = cookies.substring(s, e);
        if (message == oldmessage) {
            showMessage = false;
        }
    }

    if (showMessage && ModalDialog) {
        document.cookie = "loadmessage=" + message + "; path=/; domain=" + document.domain + ";";

        $("div#modal div.dialog div.close").unbind('click');
        $("div#modal div.dialog").unbind('click');

        $("div#modal div.dialog").html('<h3></h3><h4></h4><div id="firstDiv"><p><img src="/dynamic/assets/img/load.gif" alt="Loading..." /></p></div><div class="close"><a href="#" title="Close this dialog">close</a></div>');
        $("div#modal div.dialog div.close").hide();
        $("div#modal div.dialog h3").html(title);
        $("div#modal div.dialog h4").html(subTitle);
        $("div#modal div.dialog p:first").html(message);
        $("div#modal div.dialog div.close").show();
        $("div#modal div.dialog div.close").click(function () { ModalDialog.close(); if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } });
        $("div#modal div.dialog").click(function () { ModalDialog.close(); if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } });
       DisplayMessage();
    }
});

function DisplayMessage() {
    ModalDialog.show("modal");
    ModalDialog.resize();
}
