// CREATE AJAX OBJECT
var createObject = function() {
	var request_type;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		request_type = new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		// code for IE6, IE5
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return request_type;
};
var http = createObject();
// END OF AJAX OBJECT CREATION
//AJAX SEND QUERY
var SendQuery = function( type, srcString, pid ) {
	srcString = srcString.replace( /&/g, "|||||OCH|||||" );
	srcString = srcString.replace( /#/g, "|||||STAKET|||||" );
	srcString = encodeURI( srcString );
	nocache = Math.random();
	http.open( 'get', '/do.php?type='+type+'&src='+srcString+((pid!=false)?"&pid="+pid:"")+'&nocache = '+nocache );
	if( type == 'sourceSrc' ) {
		http.onreadystatechange = SourceShowResult;
	}
	http.send(null);
};
//END OF AJAX SEND QUERY

function slideSwitch() {
    var $active = $('#top_slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#top_slideshow DIV:last');

    var $next =  $active.next().length ? $active.next()
        : $('#top_slideshow DIV:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function reportBrokenLink() {
	var height=240,width=350;
	var divPosition = function() {
		position = {
			top: ($(window).height()-height-72)/2,
			left: ($(window).width()-width-52)/2
		};
		return position;
	};
	
	newPosition = divPosition();
	$("body").append( 
		$("<div />").attr({ 
			"id":"contactSuccess-overlay"
		}).css({
			"position":"fixed",
			"display":"inline",
			"top":0,"left":0,
			"height":$(window).height(),"width":$(window).width(),
			"background-color":"#000000",
			"opacity":0.8,
			"z-index":10000
		}),
		$("<div />").attr({ 
			"id":"contactSuccess"
		}).css({
			"position":"fixed",
			"display":"inline",
			"top":(( newPosition.top > 0 )? newPosition.top : 0 ),"left":(( newPosition.left > 0 )? newPosition.left : 0 ),
			"height":height,"width":width,
			"margin":"15px 5px",
			"padding":"5px",
			"border":"1px solid #cccccc",
			"background-color":"#ffffff",
			"z-index":10000
		}).append(
			$("<div />").css({"padding":10,"width":width-20,"height":20}).html(
				'<h1 style="margin:0;">Report broken link</h1>'
			),
			$("<div />").css({"padding":10,"width":width-20,"height":height-60,"background":"#f5f5f5"}).html(
				'<form action="" method="post" style="display:inline"><input type="hidden" name="report_broken_link" value="1">'+
				'<b>URL</b><br><input type="text" name="broken_link_url" value="'+location.href+'" class="input_text" style="width:'+(width-22)+'px;"><br><br>'+
				'<b>Description</b><br><textarea name="broken_link_description" rows="3" class="input_text" style="width:'+(width-22)+'px;"></textarea><br><br>'+
				'<div style="width:'+(width-20)+'px; text-align:center;"><input type="submit" value="Send" class="input_button"><input type="button" id="report_reset" class="input_button" value="Cancel"></div>'
			)
		)
	);
	$("#report_reset").click( function(){
		$("#contactSuccess-overlay").remove();
		$("#contactSuccess").remove();
	});
	$(window).resize(function() {
		$("#contactSuccess-overlay").css({
			"height":$(this).height(),"width":$(window).width()
		}),
		newPosition = divPosition();
		$( "#contactSuccess" ).stop().animate({
			"top":(( newPosition.top > 0 )? newPosition.top : 0 ),"left":(( newPosition.left > 0 )? newPosition.left : 0 )
		},"fast")
	});
}

$(document).ready(function(){
	// $('#language_menu').mouseover(function(){
		// $(this).stop().animate({'height':'100px'},'fast');
	// }).mouseout(function(){
		// $(this).stop().animate({'height':'30px'},'fast');
	// });
	$('#search_box').hover(
		function(){
			$(this).stop().animate({'height':'220px'},'fast');
		},
		function(){
			$(this).stop().animate({'height':'30px'},'fast');
		}
	);
});
