﻿$(document).ready(function() {
	$('#pnlForums').bind('click', function() {
		__doPostBack('', 'goto§Forums');
	});
	$('#pnlSARS').bind('click', function() {
		__doPostBack('', 'goto§SARS');
	});
	$('#pnlMembers').bind('click', function() {
		__doPostBack('', 'goto§Members');
	});
	$('#pnlStartRaid').bind('click', function() {
		__doPostBack('', 'goto§StartRaid');
	});
	$('#pnlProfile').bind('click', function() {
		__doPostBack('', 'goto§Profile');
	});
	$('#pnlGallery').bind('click', function() {
		__doPostBack('', 'goto§Gallery');
	});
	$('#pnlPersonalGallery').bind('click', function() {
		__doPostBack('', 'goto§PersonalGallery');
	});
	$('#pnlGuildSettings').bind('click', function() {
		__doPostBack('', 'goto§GuildSettings');
	});
	$('#pnlNews').bind('click', function() {
		__doPostBack('', 'goto§News');
	});
	$('#pnlSignupPanel').bind('click', function() {
		__doPostBack('', 'goto§SignupPanel');
	});
	$('#pnlSchedule').bind('click', function() {
		__doPostBack('', 'goto§Schedule');
	});

    // handles the menu system for the member profile page
	$('#divMemberMenu ul li').bind('click', function() {
		$('#divMemberProfileContent div').css('display', 'none');
		$('#div' + $(this).attr('id')).css('display', 'block');
		$('#div' + $(this).attr('id') + ' div').show();
	});
	$('#divVisitorMenu ul li').bind('click', function() {
		$('#divVisitorProfileContent div').css('display', 'none');
		$('#div' + $(this).attr('id')).css('display', 'block');
		$('#div' + $(this).attr('id') + ' div').show();
	});
	$('#divMainMenuTab').bind('mouseenter', function(){
		$('#divMainMenuTab').unbind('mouseleave');
		$('#divMainMenu').show('blind', function(){
			$('#divMainMenuTab').bind('mouseleave', function(){$('#divMainMenu').hide('blind');});
		});
	});
	
	$('.UIGRID').each(function(){
	    var xRowToggle = false;
	    
	    $(this).find('tr').each(function(){
	        if (xRowToggle){
	            $(this).addClass('OddRowColor');
	        }else{
	            $(this).addClass('EvenRowColor');
	        }
	        xRowToggle = !xRowToggle;
	    });
	});
	$('#divEditor').bind('keypress', function(){
		$('.editor').val($('#divEditor').html());
	});
	$('.editor').bind('change', function(){
		$('#divEditor').html($('.editor').val());
	});
	
	$('table.schedule td span.eventRaid').parent().addClass('hasRaid');

	//jQueryUI Assignments
	$('.UIBUTTON').button();
	$('.UICHECKBOX input:checkbox').button();
	$('.UICHECKBOX input:checkbox').bind('change', function(){
		$(this).blur();
	});
	$('.UIMODAL').dialog({
	    autoOpen: false,
	    show: {effect: 'fade', duration: 750},
	    hide: {effect: 'fade', duration:750},
	    modal: true,
	    resizable: false,
	    draggable: false,
		width: 'auto'
	}).parent().appendTo($("form:first"));
	$('.UIRADIOGROUP').buttonset();
	$('.UIBUTTONGROUP').buttonset();
	$('.UIBUTTONGROUP input:checkbox').bind('change', function(){
		$(this).blur();
	});
	$('.UIDATEPICKER').datepicker();
	$('.FULLUIACCORDION').accordion({ 
		fillSpace: true
	});
	$(".FULLUIACCORDION").accordion("resize");
	$('#editorTabs').tabs({
	   select: function(event, ui) {
		if (ui.index == 0)
			$('#divEditor').html($('.editor').val());
		if (ui.index == 1)
			$('.editor').val($('#divEditor').html());
			
		}
	});
	$('#divScheduleAccordion').liteAccordion({
		theme:				'dark',
		rounded:			true,
		easing:				'easeInOutQuart',
		containerWidth:		800,
		containerHeight:	500
	});
	$('.UITIMEPICKER').timepickr({convention: 12 });
	$('input:text').addClass('r-textbox');
	$('input:password').addClass('r-textbox');
	$('div.UIFIELDSET').each(function(){
	    $(this).addClass('rui-fieldset');
	    var html = $(this).html();
	    var width = $(this).width();
	    var height = $(this).height() + 33;
	    $(this).html('');
		var divShadow = document.createElement('div');
		var divContent = document.createElement('div');
	    
		$(divShadow).addClass('ui-widget-shadow').addClass('ui-corner-all').addClass('rui-fieldset-shadow');
		$(divContent).addClass('ui-widget').addClass('ui-widget-content').addClass('ui-corner-all').addClass('rui-fieldset-content');
		
		$(divShadow).appendTo($(this));
		$(divContent).appendTo($(this));
		
		$(divContent).html(html);
		
	    $(this).width(width);
	    $(this).height(height);
	});
	$('.bbcodeEditor').ruiEditor();
	$('.panel').each(function(){
	    $(this).addClass('rui-panel');
	    var html = $(this).html();
	    $(this).html('');
		var divTopLeft = document.createElement('div');
		var divTop = document.createElement('div');
		var divTopRight = document.createElement('div');
		var divLeft = document.createElement('div');
		var divRight = document.createElement('div');
		var divBottomLeft = document.createElement('div');
		var divBottom = document.createElement('div');
		var divBottomRight = document.createElement('div');
		var divContent = document.createElement('div');
		
		$(divTopLeft).addClass('rui-panel-top-left');
		$(divTop).addClass('rui-panel-top');
		$(divTopRight).addClass('rui-panel-top-right');
		$(divLeft).addClass('rui-panel-left');
		$(divRight).addClass('rui-panel-right');
		$(divBottomLeft).addClass('rui-panel-bottom-left');
		$(divBottom).addClass('rui-panel-bottom');
		$(divBottomRight).addClass('rui-panel-bottom-right');
		$(divContent).addClass('rui-panel-content');
		
		$(divTopLeft).appendTo($(this));
		$(divTop).appendTo($(this));
		$(divTopRight).appendTo($(this));
		$(divLeft).appendTo($(this));
		$(divRight).appendTo($(this));
		$(divBottomLeft).appendTo($(this));
		$(divBottom).appendTo($(this));
		$(divBottomRight).appendTo($(this));
		$(divContent).appendTo($(this));
		
		$(divContent).html(html);
	});
});

var inOperations_Scheduling = false;
function openScheduling(openElementID){
	if(inOperations_Scheduling){
		setTimeout("openScheduling(" + openElementID + ")", 500);
		return false;
	}
	else
		inOperations_Scheduling = true;
	var closingDiv = false;
	$('.divScheduling').filter(':visible').each(function(){
		closingDiv = true;
		if($(this).attr('id') == openElementID){
			$(this).hide('slide');
			inOperations_Scheduling = false;
			return false;
		}
		$(this).hide('slide').queue(function(){
			$('#' + openElementID).show('slide');
			$(this).dequeue();
			inOperations_Scheduling = false;
		});
	});
	if (!closingDiv){
		$('#' + openElementID).show('slide');
		inOperations_Scheduling = false;
	}
	return false;
}
	
function openDialog(divID){
    $('#' + divID).dialog('open');
    return false;
}

function closeDialog(divID){
    $('#' + divID).dialog('close');
    return false;
}

var confirmedDialog = false;
var confirmButton;
function confirmDialog(obj, title, message)
{
	if (!confirmedDialog){
		confirmButton = obj;
		var x = $('<div id="divDialog" title="' + title + '" class="divModalConfirm"><p>' +  message + '</p></div>');
		$('body').append(x);
		$(x).dialog({
			resizable: false,
			draggable: false,
			show: {effect: 'fade', duration: 750},
			hide: {effect: 'fade', duration: 250},
			modal: true,
			buttons: {
				"Yes": function()
				{
					$( this ).dialog( "close" );
					confirmedDialog = true;
					setTimeout('confirmButton.click();', 250);
				},
				"No": function()
				{
					$( this ).dialog( "close" );
				}
			}
		}).parent().appendTo($("form:first"));
		$('#divDialog').parent().find('button').addClass('CONFIRMBUTTONS');
	}else{
		confirmedDialog = false;
		return true;
	}
	
	return false;
}

function AddSMTH () {
	var textarea = $('.editor')[0];
	if (textarea.selectionStart === undefined) {	// Internet Explorer
			// create a range from the current selection
		var textRange = document.selection.createRange ();
			// check whether the selection is inside the textarea element
		var rangeParent = textRange.parentElement ();
		if (rangeParent && rangeParent.id == "test") {
				// add [smth] around the selected text
			textRange.text = "[smth]" + textRange.text + "[/smth]";

		}
	}
	else {
			// check whether some text is selected inside the textarea element
		if (textarea.selectionStart != textarea.selectionEnd) {
			var newText = textarea.value.substring (0, textarea.selectionStart) + 
						"[smth]" + textarea.value.substring  (textarea.selectionStart, textarea.selectionEnd) + "[/smth]" +
						textarea.value.substring (textarea.selectionEnd);
			textarea.value = newText;
		}
	}
}


// Image preloader for the site

$.preloadImages = function()  
{         
    for(var i = 0; i<arguments.length; i++)         
    {                 
    $("<img />").attr("src", arguments[i]);         
    }  
}    
    $(document).ready(function()  
{         
    $.preloadImages(
        "images/logo.jpg",
        "images/banner_images/webbanner_01.png",
        "Images/forum_bg.jpg",
        "Images/forum_sides.png",
        "Images/symbol_separator.png",
        "Images/symbol_separator2.png",
        "Images/dromund-kaas.jpg",
        "Images/bar_transition_img.jpg",
        "Images/background_grid.png",
        "Images/Banner_bar.png",
        "Images/panel_bg.png",
        "Images/panel_top_left.png",
        "Images/panel_top_bar.png",
        "Images/panel_top_right.png",
        "Images/panel_left_bar.png",
        "Images/panel_right_bar.png",
        "Images/panel_bottom_left.png",
        "Images/panel_bottom_bar.png",
        "Images/panel_bottom_right.png"
    );  
});  
