$(document).ready(function()
{
    // replace headings with flash alternatives
    sIFR.replaceElement("h1", named( 
                                    {
                                     sFlashSrc: "/common/js/sifr/verdana.swf",
                                     sBgColor:  "#ffffff",
                                     sColor:    "#313131",
                                     /*sCase:     "upper",*/
                                     sWmode:    "opaque"
                                    }
                                   )
                           );
    // replace headings with flash alternatives
    sIFR.replaceElement("h2", named( 
                                    {
                                     sSelector: ".flashTitleContentBlock",
                                     sFlashSrc: "/common/js/sifr/verdana.swf",
                                     sBgColor:  "#f5f5f5",
                                     sColor:    "#313131",
                                     /*sCase:     "upper",*/
                                     sWmode:    "opaque"
                                    }
                                   )
                       );
                       
    // replace headings with flash alternatives
    sIFR.replaceElement("h3", named( 
                                    {
                                     sFlashSrc: "/common/js/sifr/verdana.swf",
                                     sBgColor:  "#f5f5f5",
                                     sColor:    "#313131",
                                     /*sCase:     "upper",*/
                                     sWmode:    "opaque"
                                    }
                                   )
                       );

    /**
     * Open any link with rel="window" in a new window
     */
    $('a[class="link"]').click(
        function()
        {
            window.open( this.href );
            return false;
        }
    );
        
	// loop through each li element in the navigation
	$('#nav ul li').each(function() {
		
		// get colour information
		// deals with pre selected pages
		var temp = $('a', this).css("color");
		var temp = temp.slice(4, 7);
		var num = parseInt(temp);
		

		if(num != 333) {
			// deal with hovering over the li	
			$(this).hover(
				function(){
					if(num == 51){}
					else {
					// remove the bullet from the 'a'
					$('a', this).css({"background":"none"});
					// add the hover class
					$(this).addClass("hover");
					}
				}, 
				function(){
					if(num == 51){}
					else {
					// add back the bullet
					$('a', this).css({"background":"url(/images/icons/bullet_white.png) no-repeat",
							  "background-position":"25px 5px"});
					// remove the hover class
					$(this).removeClass("hover");
					}
			});
		}
	});
	
	$('#username').click(function(){
		if(this.value == 'email') {
			this.value = '';
		}
	});
	$('#username').blur(function(){
		if(this.value == '') {
			this.value = 'email';
		}
	});
	$('#password').click(function(){
		if(this.value == 'password') {
			this.value = '';
		}
		});
	$('#password').blur(function(){
		if(this.value == '') {
			this.value = 'password';
		}
	});
	
	$('#personalView').hide();
	// on click toggle the companies on/off
	$('.personalToggle').click(function() {
		$('#personalView').slideToggle("normal");
		return false;
	});
	
	$('#activeDesignView').hide();
	// on click toggle the companies on/off
	$('.activeDesignToggle').click(function() {
		$('#activeDesignView').slideToggle("normal");
		return false;
	});
	
	$('#adCampaignView').hide();
	// on click toggle the companies on/off
	$('.adCampaignToggle').click(function() {
		$('#adCampaignView').slideToggle("normal");
		return false;
	});
	
	$('#serviceView').hide();
	// on click toggle the companies on/off
	$('.serviceToggle').click(function() {
		$('#serviceView').slideToggle("normal");
		return false;
	});
	
	$('#marketView').hide();
	// on click toggle the companies on/off
	$('.marketToggle').click(function() {
		$('#marketView').slideToggle("normal");
		return false;
	});
	
	$('#motorsView').hide();
	// on click toggle the companies on/off
	$('.motorsToggle').click(function() {
		$('#motorsView').slideToggle("normal");
		return false;
	});	

	$('#propertyView').hide();
	// on click toggle the companies on/off
	$('.propertyToggle').click(function() {
		$('#propertyView').slideToggle("normal");
		return false;
	});

	$('#classifiedView').hide();
	// on click toggle the companies on/off
	$('.classifiedToggle').click(function() {
		$('#classifiedView').slideToggle("normal");
		return false;
	});
	
	$('#eventsView').hide();
	// on click toggle the companies on/off
	$('.eventsToggle').click(function() {
		$('#eventsView').slideToggle("normal");
		return false;
	});
	
	$('#jobsView').hide();
	// on click toggle the companies on/off
	$('.jobsToggle').click(function() {
		$('#jobsView').slideToggle("normal");
		return false;
	});		

	/*
	 * Deal with add profile
	 */
	 $(".textarea_history").hide();
	 $("#profileHistory > .toggleHistory").click(function() {
			$(".textarea_history").show();
			$("#profileHistory > .toggleHistory").hide();
			return false;
		});
	$(".textarea_services").hide();
	$("#profileServices > .toggleServices").click(function() {
			$(".textarea_services").show();
			$("#profileServices > .toggleServices").hide();
			return false;
		});
	$(".textarea_products").hide();
	$("#profileProducts > .toggleProducts").click(function() {
			$(".textarea_products").show();
			$("#profileProducts > .toggleProducts").hide();
			return false;
		});
	$(".profileImagesView").hide();
	$("#profileImages > .toggleImages").click(function() {
			$(".profileImagesView").show();
			$("#profileImages").hide();
			return false;
		});
	
	/*
	 * Deals with registration form
	 */ 
	
    //hide unneded rows to start
    //$(".org_name").hide();
    //$(".website").hide();
    var accSelect = $('#type');
    accSelect.change(function() {
		var accSelect = document.getElementById('type');
    	var selectedVal = accSelect.options[accSelect.selectedIndex].value;
    
    	if(selectedVal != 1){
    	    $(".org_name").show();
    	    $(".website").show();
    	} else{
    	    $(".org_name").hide();
    	    $(".website").hide();
    	}
	});
	
	/**
	 * Deals with the Magazine Page
	 */
	// hide all details for the events magazine page
	$('.details').hide();
	// assign an onclick event handler
	$('.toggle').click(function(){
		// grab the class name
		var cName = $(this).attr("class");
		// split the name to get the toggle number
		cName = cName.split(' ');
		// create a div name with the number
		var className = ".div"+cName[1];
		// slide open the correct div
		$(className).slideToggle();
	});
	// stripe table
	$('.details > table tr:odd').addClass('odd');
});