﻿/// <reference path="../_scripts/jquery-1.4.2-vsdoc.js" />

$(document).ready(function() {

    $('span.controls').click(function() {
        $('div.modalmask').hide('fast');
    });

    $('#contact').click(function() {
        $('div.modalmask').show('fast');
    });
    

    $.ajax({
        type: "GET",
        url: "_content/content.xml",
        dataType: "xml",
        success: function(xml) {
            test(xml, 'homepage');
        }
    });

    $.jGFeed('http://www.proprint.com.au/RSS/rss.ashx?ID=215',
       function(feeds) {
           if (!feeds) {
               return false;
           }
           for (var i = 0; i < feeds.entries.length; i++) {
               var entry = feeds.entries[i];
               $('div.rss').append('<a  href="' + entry.link + '" target="_blank">' + entry.title + '</a>');
               $('a:even').addClass('dark');
           }
       }, 5);

    $('a', '#nav li.button').fadeOut(0);

    $('#home').click(function() {
        location.reload();
    });

    $('#nav li').hover(
		function() {
		    //show its submenu
		    $('ul', this).slideDown(100);
		},
		function() {
		    //hide its submenu
		    $('ul', this).slideUp(100);
		}
	);

    $('#nav li span').click(function() {

        var x = $(this).attr('id');

        $.ajax({
            type: "GET",
            url: "_content/content.xml",
            dataType: "xml",
            success: function(xml) {
                test(xml, x);
            }
        });        
    }
    );

    $('#nav li ul li span').click(function() {

        var x = $(this).attr('id');

        $.ajax({
            type: "GET",
            url: "_content/content.xml",
            dataType: "xml",
            success: function(xml) {
                test(xml, x);
            }
        });

        $($(this).parent().parent()).slideUp(100);
    }
    );

});

function test(xml, id) {
    $('div.images').children().remove();
    $('div.text').children().remove();
    $(xml).find('page[id=' + id + ']').each(function() {
        if (id != 'homepage') {
            $('div.rss').remove();
        }
        $('h1').text($(this).find('title').text());


        //$('p').text($(this).find('text').text());

        $(this).find('paragraph').each(function() {
            $('div.text').append('<p>' + $(this).text() + '</p>')
        });

        $(this).find('image').each(function() {
            $('div.images').append('<img src="' + $(this).text() + '" />')
    })
    
        $('div.body').css('border-right', 'solid 12px #' + $(this).find('colour').text());
        // $('div.content').css('background-color', '#' + $(this).find('bgcolour').text());
    });
}




