
var index = 2;
jQuery().ready(function(){

	//var listItem = $('#bar');
	//alert('Index: ' + $('li').index(listItem));

	// second simple accordion with special markup
	jQuery('#navigation').accordion({
		autoheight: false,
		active: indexDefault,
		header: '.head',
		navigation: true,
		event: 'none',
		fillSpace: false,
		animated: 'easeslide'
	});
	
	$('#advert_slide').innerfade({ animationtype: 'fade', speed: 1000, timeout: 7000, type: 'random' });
	
	//LOADING POPUP
	//Click the button event!
	$("#ctl00_lnkLanguage").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		
		return false;
	});
		
	
			
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
}); 
		

$(document).ready(function() {
	
	$tabs = $("#featured > ul").tabs({ fx: {opacity: 'toggle', duration: 'slow'} }).tabs('rotate', 4000);
	
	$(".ui-tabs-panel").each(function(i){
	
	  var totalSize = $(".ui-tabs-panel").size() - 1;

	  if (i != 0) {
		  prev = i;
		  //$(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a>");
		  $(this).append("<div class='prev-tab mover' rel='" +prev + "'>&nbsp;&nbsp;</div>");
	  } else {
		$(this).append("<div class='prev-tab mover' rel='" + (totalSize + 1) + "'>&nbsp;&nbsp;</div>");
	  }
	  
	  if (i != totalSize) {
		  next = i + 2;
		  //$(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a>");
		  $(this).append("<div class='next-tab mover' rel='" + next + "'>&nbsp;&nbsp;</div>");
	  }	  
	  else
	  {
		$(this).append("<div class='next-tab mover' rel='" + "0" + "'>&nbsp;&nbsp;</div>");
	  }

	});

	$('.next-tab, .prev-tab').click(function() { 
		   $tabs.tabs('select', $(this).attr("rel"));
		   $tabs.tabs('rotate', 0, false)
		   return false;
	});	
	
	
	$('#changecountry').click(function() {		
	  $('#changecountrytoggle').toggle('slow', function() {
	  	var innerhtml = $('#changecountry').html();
	  	
	  	if (innerhtml == SBPhrases["CHANGE_COUNTRY1"])
	  	{
	  		$("#drpCountryHome").msDropDown();	  		
	  		$('#changecountry').html(SBPhrases["CHANGE_COUNTRY2"]);
	  		
	  	}
	  	else
	  		$('#changecountry').html(SBPhrases["CHANGE_COUNTRY1"]);
	    // Animation complete.
	  })
	  return false;
	});
		
	
	$(".divThumbnails img").click(function() {
		var largePhoto = $(".largePhoto")[0];
		var newImage = this.src.replace("width=100", "height=320");
		$(".largePhoto").fadeOut(500, function() {
			var img = new Image();
			img.onload = new function() {
				largePhoto.src = newImage;
				setTimeout("$('.largePhoto').fadeIn()", 500);
			}
			img.src = newImage;
		});
	});
		
	var s = document.getElementById("drpCountry");		
	var t = document.getElementById("drpCountryHome");
	var hidCountryKey = document.getElementById("ctl00_hidCountryKey");

	var index = 0;
	for (var i = 0; i < s.options.length; i++ ) {        
		if (s.options[i].value == hidCountryKey.value) {       
			index = i;
		}    
	}
	
	s.selectedIndex = index;	
	
	if (t)
		t.selectedIndex = index;
		
	$("#drpCountry").msDropDown();	
	
	var Country = document.getElementById("Country");
	if (Country)
		Country.innerHTML = countryRecords[index];
				
	var u = document.getElementById("drpItemsByPage");
	var hidItemsByPage = document.getElementById("ctl00_hidItemsByPage");
	index = 0;
	if (u)
	{
		for (var i = 0; i < u.options.length; i++ ) {        
			if (u.options[i].value == hidItemsByPage.value) {       
				index = i;
			}    
		}
		u.selectedIndex = index;		
	}
});

function enabledButton(sender)
{	

	var u = document.getElementById("ctl00_hidClicked");
	
	if (u.value == "1")
	{
		return false;
	}
	else
	{
		u.value = "1";
		return true;
	}
	
}

function showValue(sender)
{	
	var form = document.createElement("form"); 
	
	form.setAttribute("method", "POST");      
	//form.setAttribute("action", windows.location);      
	
	var hiddenField = document.createElement("input");        
    hiddenField.setAttribute("type", "hidden");         
    hiddenField.setAttribute("name", "hidName");         
    hiddenField.setAttribute("value", "CountryKey|" + sender);
    form.appendChild(hiddenField);     
	
	document.body.appendChild(form);     
	form.submit();
}

function changeItemsByPage(sender)
{	
	var form = document.createElement("form"); 
	
	form.setAttribute("method", "POST"); ;   
	//form.setAttribute("action", windows.location);      
		
	var hiddenField = document.createElement("input");        
    hiddenField.setAttribute("type", "hidden");         
    hiddenField.setAttribute("name", "hidName");         
    hiddenField.setAttribute("value", "ItemsByPage|" + sender.options[sender.selectedIndex].value);
    form.appendChild(hiddenField);     	
	document.body.appendChild(form);     
	form.submit();
}

function login()
{
	var security = new SpringBoard.Security();
	
	var UserName = document.getElementById("txtUserName");
	var Password = document.getElementById("txtPassword");
	
	security.UserLogin(UserName.value, Password.value, UserLogin_CallBack);
}

function UserLogin_CallBack(succes)
{
	if (succes)
		document.location = SBPhrases["LNK_DOCUMENTS"];		
	else
		alert(SBPhrases["LGN_BADPASS"]);	
}

function logout()
{
	var security = new SpringBoard.Security();	

	security.UserLogout();
	document.location = "/";	
}

function UserLogout_CallBack()
{

}


function submitenter(myfield,e) {         
	var keycode;         
	if (window.event) 
		keycode = window.event.keyCode;         
	else if (e) keycode = e.which;         
	else return true;          
	if (keycode == 13) {             
		login();
		return false;         
	}         
	else             
		return true;     
}
