var  $$ = jQuery.noConflict();

//write cookie for user resolution
function writeCookie() {
	 var today = new Date();
	 var the_date = new Date("December 31, 2023");
	 var the_cookie_date = the_date.toGMTString();
	 var availheight=screen.availHeight;
     var availwidth=screen.availWidth;
     var colordepth=screen.colorDepth + "bit";
	 var pixeldepth=screen.pixelDepth + "bit";
	 var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
	 var the_cookie = the_cookie + ";path=/;expires=" + the_cookie_date;
	 document.cookie=the_cookie
}
if (document.cookie.indexOf('users_resolution') != ''){
	writeCookie();
}

 
//search functions
if (!applesearch)	var applesearch = {};
applesearch.onChange = function (fldID, btnID){
	var fld = document.getElementById( fldID );
	var btn = document.getElementById( btnID );
	if (fld.value.length > 0 && !this.clearBtn)
	{
		btn.style.backgroundImage = "url('" + window.location.protocol + "//" + window.location.host+"/themes/morien/images/login_sprite.gif')";
		btn.style.backgroundPosition = "0 0";
		btn.fldID = fldID;
		btn.onclick = this.clearBtnClick;
		this.clearBtn = true;
        btn.style.cursor = "pointer";
	} else if (fld.value.length == 0 && this.clearBtn){
		btn.style.backgroundImage = "url('" + window.location.protocol + "//" + window.location.host+"/themes/morien/images/login_sprite.gif')";
		btn.style.backgroundPosition = "-19px 0";
		btn.onclick = null;
        btn.style.cursor = "default";
		this.clearBtn = false;
	}
}

applesearch.clearFld = function (fldID,btnID){
	var fld = document.getElementById( fldID );
	fld.value = "";
	this.onChange(fldID,btnID);
}
applesearch.clearBtnClick = function (){
	applesearch.clearFld(this.fldID, this.id);
}
$$(document).ready(function(){
		
		
	//image hover
	$$('#language img').hover(
		function () {
			var imghover = $$(this).attr("src").replace(".gif","_hover.gif");
			$$(this).attr("src",imghover);
		},
		function () {
			var imghover = $$(this).attr("src").replace("_hover.gif",".gif");
			$$(this).attr("src",imghover);
		}
	);

	//image hover
	$$('img.logo').hover(
		function () {
			var imghover = $$(this).attr("src").replace(".png","_hover.png");
			$$(this).attr("src",imghover);
		},
		function () {
			var imghover = $$(this).attr("src").replace("_hover.png",".png");
			$$(this).attr("src",imghover);
		}
	);
	
	//slider	
	$$.featureList(
		$$("#tabs li a"),
		$$("#output li"), {
			start_item	:	0
		}
	);
		

	$$(".sbox_r").click(function() {
			document.forms["searchForm"].submit();
	});
	
	/*$$('#logos img').hover(function(){
		var source = $$(this).attr('src').replace("normal", "hover");
		$$(this).attr('src',source);
	},
  function () {
   	var source = $$(this).attr('src').replace("hover", "normal");
		$$(this).attr('src',source);
  });*/
});
function slideSwitch() {
    var $$active = $$('#slideshow IMG.active');

    if ( $$active.length == 0 ) $$active = $$('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $$next =  $$active.next().length ? $$active.next()
        : $$('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


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

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

$$(function() {
    setInterval( "slideSwitch()", 5000 );
});
