if ($("#feature_container").length > 0){		// if feature is present

	var containers = $("#feature_container > div").size();  // items, will always work unless HTML is changed
	var f_count = 1;
	var w = $(".featureBoxNew").width();  // container width
	var when = 5000;  // change every # ms
 
	var t=setTimeout("toggle_feature()",when)
}

function updateQuote() {
    alert(0);

}

// edit links
function getSelectionStartNode() {
    var node, selection;
    if (window.getSelection) { // FF3.6, Safari4, Chrome5 (DOM Standards)
        selection = getSelection();
        node = selection.anchorNode;
    }
    if (!node && document.selection) { // IE
        selection = document.selection
        var range = selection.getRangeAt ? selection.getRangeAt(0) : selection.createRange();
        node = range.commonAncestorContainer ? range.commonAncestorContainer :
           range.parentElement ? range.parentElement() : range.item(0);
    }
    if (node) {
        return (node.nodeName == "#text" ? node.parentNode : node);
    }
}


$(function () {


    function pausecomp(millis) {
        var date = new Date();
        var curDate = null;
        do { curDate = new Date(); }
        while (curDate - date < millis);
    }


    var contents = $('.quote').html();
    $('.quote').blur(function () {
        if (contents != $(this).html()) {
            var theHtml = $(this).html();
            //theHtml = theHtml.replace("<strong>", "[b]");
            //theHtml = theHtml.replace("</strong>", "[/b]");
            $("#quoteTxt").val(theHtml);
            contents = $(this).html();
        }
    });


    $('#Submit2').click(function () {
        var contents2 = $('#maintxt').html();
        $("#editContent").val(contents2);
        pausecomp(300);
    });




    $("#editLink").hide();
    $("#scedit").bind('keyup click', function (e) {
        var $node = $(getSelectionStartNode());
        if ($node.is('a')) {
            $("#editLink").css({
                top: $node.offset().top - $('#editLink').height() - 5,
                left: $node.offset().left
            }).show().data('node', $node);
            $("#linktext").val($node.text());
            $("#linkhref").val($node.attr('href'));
            $("#linkpreview").attr('href', $node.attr('href'));
        } else {
            $("#editLink").hide();
        }
    });
    $("#linktext").bind('keyup change', function () {
        var $node = $("#editLink").data('node');
        $node.text($(this).val());
    });
    $("#linkhref").bind('keyup change', function () {
        var $node = $("#editLink").data('node');
        //$node.and('#linkpreview').attr('href', $(this).val());
        $node.attr('href', $(this).val());
    });



    if ($("#right").attr("src") == "images/maps/master.gif") {  // if on main page

        var countries = ["uk", "sweden", "spain", "netherlands", "poland", "italy", "ireland", "germany", "france", "finland", "denmark", "belgium"];  // countries on map

        $("li").mouseover(function () {
            var cClass = $(this).attr("class");
            if (jQuery.inArray(cClass, countries) > -1) {		// if li class is a country
                $("#right").attr("src", "images/maps/" + cClass + ".gif");
            }
        }).mouseout(function () {
            var cClass = $(this).attr("class");
            if (jQuery.inArray(cClass, countries) > -1) {
                $("#right").attr("src", "images/maps/master.gif");
            }
        });

        $("li").click(function () {
            var id = $(this).attr("id");
            window.location = 'setLanguage.aspx?lang=' + id;
        });
    }


    /* placeholder support for IE */

    $('[placeholder]').focus(function () {
        var input = $(this);
        if (input.val() == input.attr('placeholder')) {
            input.val('');
            input.removeClass('placeholder');
        }
    }).blur(function () {
        var input = $(this);
        if (input.val() == '' || input.val() == input.attr('placeholder')) {
            input.addClass('placeholder');
            input.val(input.attr('placeholder'));
        }
    }).blur();

    $('[placeholder]').parents('form').submit(function () {
        $(this).find('[placeholder]').each(function () {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                input.val('');
            }
        })
    });


});


function toggle_feature() {

		if (f_count == containers) {	// if final
				$("#feature_container").animate({"right": "0px"}, "slow"); // go back to start
				f_count = 1;
				$(".list li a").removeClass("hoverc");
				$(".list li a:eq(0)").toggleClass("hoverc");
				setTimeout("toggle_feature()",when);	// recurse
		} else {
			var math = (w * f_count) + "px";
			$("#feature_container").animate({"right": math}, "slow", function(){
				f_count ++;
				var jquerystr = ".list li a:eq(" + (f_count-1) + ")";
				$(".list li a").removeClass("hoverc");
				$(jquerystr).toggleClass("hoverc");

				setTimeout("toggle_feature()",when);
			});
		}
}

function toggleIt(num){
		var containers = $("#feature_container > div").size() -1;
		if (num > containers)  num = 0;

		math = (w * num) + "px";
		$("#feature_container").animate({"right": math}, "slow");
		$("#feature_container").clearQueue();
		f_count = num;

		$(".list li a").removeClass("hoverc");
		var jquerystr = ".list li a:eq(" + (f_count) + ")";
		$(jquerystr).toggleClass("hoverc");
}

if ($.browser.msie && $.browser.version.substr(0, 1) <= 7) {
    $("hr").replaceWith('<div class="hr"></div>');
}

