$(function() {
    $('input[id$=btnTopSearch]').bind('click', function(event) {
        var obj = $('input[id$=tbQuery]')
        if (obj.attr('orgValue') != undefined && obj.val() == obj.attr('orgValue')) {
            obj.val('');
        }
        window.location = "/Search.aspx?query=" + encodeURIComponent(obj.val());
        return false;
    });
    
    $('input[id$=tbQuery]').bind('focus', function(event) {

        var obj = $('input[id$=tbQuery]')
        if (obj.attr('orgValue') == undefined) {
            obj.attr("orgValue", obj.val())
        }
        if (obj.val() == obj.attr('orgValue')) {
            obj.val('');
        }
    });

    $('input[id$=tbQuery]').bind('blur', function(event) {
        var obj = $('input[id$=tbQuery]')
        if (obj.val() == "") {
            if (obj.attr('orgValue') != undefined) {
                obj.val(obj.attr('orgValue'));
            }
        }
    });

    $('input[id$=tbQuery]').bind('keypress', function(event) {
        var obj = $('input[id$=tbQuery]')
        if (event.keyCode == 13) {

            window.location = "/Search.aspx?query=" + encodeURIComponent(obj.val());
            return false;
        }
        return true;
    });

    $("input[id$=tbQuery]").autocomplete("/SearchPreview.ashx", {
        minChars: 3,
        width: 200,
        max: 30,
        highlight: false,
        selectFirst: false,
        scrollHeight: 300,
        formatItem: function(data, i, n, value) {
            var myObject = eval('(' + value + ')');
            return "<strong>" + myObject.title + "</strong><br />" + myObject.manchet;
        },
        formatResult: function(data, value) {
            var myObject = eval('(' + value + ')');
            return myObject.title;
        }
    });

    $("input[id$=tbQuery]").result(function(event, data, formatted) {
        if (data) {
            var myObject = eval('(' + data + ')');
            window.location = myObject.url;
        }
    });

    $("#tipfriend,.sendToFriend").click(function() {
        var args = "", xposition = 0, yposition = 0, width = 300, height = 350;
        if (parseInt(navigator.appVersion) >= 4) {
            xposition = (screen.width - width) / 2;
            yposition = (screen.height - height) / 2;
        }
        args += 'width=' + width + ',height=' + height + ',screenx=' + xposition + ',screeny=' + yposition + ',';
        args += 'left=' + xposition + ',top=' + yposition + ',';
        args += 'scrollbars=1,location=0,menubar=0,resizable=1,status=0,titlebar=0,toolbar=0,hotkeys=0,directories=0';
        window.open(this.href, "tipFriend", args, false);
        return false;
    });

});

$(document).ready(function(){
		
   $('#imagegallery').jCarouselLite({
      btnNext: '#imagegalleryleft',
      btnPrev: '#imagegalleryright'
   });
	$('.col').pngFix();
	
	$('.goToUrlFromSelect').goToUrlFromSelect();
	$('.goToValueOnChange').goToValueOnChange();

});

$.fn.goToUrlFromSelect = function() {
	currentForm = this;
	$("select", this).bind("change", function(event) {
		currentForm.submit();
	}),
	this.bind("submit", function(event) {
		selectedOption = $(":selected", this);
		window.location = selectedOption.val();
		return false;
	});
	return this;
};

$.fn.goToValueOnChange = function() {
	return this.bind("change", function(event) {
		window.location = this.value;
	});
};


