
/// <reference path="script.js" />
/// <reference path="GSK.PopupManager.js" />

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Title : GSK Functions
// Author : Rapp UK
//
// Description : Core functionality for standard sites developed by Rapp UK
//
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//initiate slider control
//$(function()
//{
//	$('#slider_callout').hide();
//	var calloutVisible = false;
//	$('.slider_bar').slider({
//		handle: '.slider_handle',
//		minValue: 0,
//		maxValue: 25,
//		start: function(e, ui)
//		{
//			$('#slider_callout').fadeIn('fast', function() { calloutVisible = true; });
//		},
//		stop: function(e, ui)
//		{
//			if (calloutVisible == false)
//			{
//				$('#slider_callout').fadeIn('fast', function() { calloutVisible = true; });
//				$('#slider_callout').css('left', ui.handle.css('left')).text(Math.round(ui.value));
//			}
//			$('#slider_callout').fadeOut('fast', function() { calloutVisible = false; });
//		},
//		slide: function(e, ui)
//		{
//			$('#slider_callout').css('left', ui.handle.css('left')).text(Math.round(ui.value));
//		}
//	});
//});

//modal windows
Sys.Application.add_load(function()
{
    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e)
    {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });
        $('#select-free').css({ 'width': maskWidth, 'height': maskHeight }).show();
        //transition effect		
        $('#mask').fadeIn(200);
        $('#mask').fadeTo("fast", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).outerHeight() / 2);
        $(id).css('left', winW / 2 - $(id).outerWidth() / 2);

        //transition effect
        $(id).fadeIn(500);

    });

    //if close button is clicked
    $('.window .close2').click(function(e)
    {
        //Cancel the link behavior
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
        $('#select-free').hide();
    });

    //if mask is clicked
    $('#mask').click(function()
    {
        $(this).hide();
        $('.window').hide();
        $('#select-free').hide();
    });
});
Sys.Application.add_load(function(sender, arg)
{
    if (arg.get_isPartialLoad())
        return;

    //select all the a tag with name equal to modal
    $('a[name=modal2]').click(function(e)
    {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('hash');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });
        $('#select-free').css({ 'width': maskWidth, 'height': maskHeight }).show();
        //transition effect  
        $('#mask').fadeIn(200);
        $('#mask').fadeTo("fast", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
        var scrollTop = $(window).scrollTop();

        $('form').append($(id));

        //Set the popup window to center
        var top = winH / 2 - $(id).outerHeight() / 2;
        var left = winW / 2 - $(id).outerWidth() / 2;

        if (top < 0) top = 10;
        if (left < 0) left = 10;

        $(id).css('top', scrollTop + top);
        $(id).css('left', left);

        //transition effect
        $(id).fadeIn(500);

    });

    //if close button is clicked
    $('.window .close2').click(function(e)
    {
        //Cancel the link behavior
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
        $('#select-free').hide();
    });

    //if mask is clicked
    $('#mask').click(function()
    {
        $(this).hide();
        $('.window').hide();
        $('#select-free').hide();
    });
});

PEPS = {};
PEPS.rollover =
{
    selector: null,
    init: function(selector)
    {
        this.selector = selector;
        //this.preload();

        var images = $(selector);

        for (var i = 0; i < images.length; i++)
        {
            var elem = $(images.get(i));
            if (elem.attr('src').indexOf('-o.') < 0)
            {
                elem.hover(
				 function()
				 {
				     var elem = $(this);
				     if (elem.attr('src').indexOf('-o.') < 0)
				     {
				         if (elem.attr('src').indexOf('blank.gif') > -1)
				         {
				             var src = PEPS.rollover.parseFilter(elem.css('filter'));
				             elem.attr('src', PEPS.rollover.newimage(src));
				         }
				         else
				         {
				             elem.attr('src', PEPS.rollover.newimage($(this).attr('src')));
				         }
				     }
				 },
				 function()
				 {
				     var elem = $(this);
				     if (elem.attr('src').indexOf('blank.gif') > -1)
				     {
				         var src = PEPS.rollover.parseFilter(elem.css('filter'));
				         elem.attr('src', PEPS.rollover.oldimage(src));
				     }
				     else
				     {
				         elem.attr('src', PEPS.rollover.oldimage($(this).attr('src')));
				     }
				 }
				);
            }
        }
    },

    preload: function()
    {
        $(window).bind('load', function()
        {
            $(selector).each(function(key, elm) { $('<img>').attr('src', PEPS.rollover.newimage($(this).attr('src'))); });
        });
    },

    newimage: function(src)
    {
        return src.substring(0, src.search(/(\.[a-z]+)$/)) + '-o' + src.match(/(\.[a-z]+)$/)[0];
    },

    oldimage: function(src)
    {
        return src.replace(/-o\./, '.');
    },

    parseFilter: function(src)
    {
        //src = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://localhost/images/navigation/understand.png",sizingMethod="scale")';
        src = src.substr(src.indexOf('//') + 2);
        src = src.substr(src.indexOf('/'));
        return src.substr(0, src.toLowerCase().indexOf('.png') + 4);
    }
};


function pageup(e)
{
//    UAGENT = navigator.userAgent.toUpperCase();
//    if (UAGENT.indexOf("MSIE") >= 0) { posi = event.y; }
//    else { posi = e.pageY; }

    moveObje($(window).scrollTop());
}

function moveObje(position)
{
    move = position / 15;
    point = parseInt(position - move);
    scrollTo(0, point);
    if (point > 0) { setTimeout("moveObje(point)", 15); }
}

function externalLinks()
{
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++)
    {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
            anchor.target = "_blank";
    }
}

window.onload = externalLinks;



