﻿jQuery(document).ready(function () {
jQuery('div.chrome').addClass("ui-widget-content");
jQuery('div.chrome div.content_area').addClass("ui-widget");
//jQuery('div.legend h6').addClass("ui-state-active"); 
//jQuery('a[href*="http"]').addClass("externallink");  
jQuery(".button").button();
});

jQuery(function () {
    jQuery('html').attr('dir', 'ltr');
    //jQuery('.gtr').translate('en', 'fr');
  
});

$(document).ready(function () {
$('img').error(function () {
$(this).hide();
});
});

$(document).ready(function () {
    if ((screen.width >= 1024) && (screen.height >= 768)) {
        //alert('Screen size: 1024x768 or larger');
        //$("link[rel=stylesheet]:not(:first)").attr({ href: "/_app/Skins/skin_cms/css/global.css" });
    }
    else {
        //alert('Screen size: less than 1024x768, 800x600 maybe?');
        //$("link[rel=stylesheet]:not(:first)").attr({ href: "/_app/Skins/skin_cms/css/global800.css" });
    }
});


$(document).ready(function () {
    jQuery('#themes-list').hide();
    jQuery('#themes').click(function () {
        jQuery('#themes-list').toggle();
        return false;
    });
    jQuery('#themes-list').toggle(function () {
        jQuery('#themes-list').show();
    },
        function () {
            jQuery('#themes-list').show();
        });


    jQuery('#styleswitch1').change(function () {
        switchStylestyle($('#styleswitch1 :selected').text());

        return false;
    });
    var c = readCookie('style');
    if (c)
        switchStylestyle(c);
});



function switchStylestyle(styleName) {
    $(".jqtheme").attr('href', '/css/' + styleName + '/jquery-ui.css');
    createCookie('style', styleName, 365);
}
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
function eraseCookie(name) {
    createCookie(name, "", -1);
}


function displayUser() {
    //if (Sys.Services.AuthenticationService.get_isLoggedIn()) {
    //Sys.Services.AuthenticationService.get_isLoggedIn();
    jQuery('#signin-button').removeClass().addClass("ui-icon ui-icon-circle-triangle-s");
    jQuery('#signin-form').hide();
    //jQuery('#signin-button').hide();
    //jQuery('#signin-header').hide();
    //jQuery('#signin-area').hide();
    jQuery('#current-user').show();
    //jQuery('#register').hide();

    // }
    // else {
    //            jQuery('#signin-button').removeClass().addClass("ui-icon ui-icon-circle-triangle-s");
    //            jQuery('#signin-form').hide();
    //            jQuery('#current-user').hide();
    jQuery('#signin-area').show();
    jQuery('#signin-header').show();
    jQuery('#register').show();
    // }
}

jQuery(document).ready(function () {


    if (typeof (Sys) !== "undefined")
        Sys.Application.notifyScriptLoaded();
    displayUser();

    jQuery('#signin-submit').click(function () {
        OnLogin();
        return false;
    });
    jQuery('#signout-submit').click(function () {
        OnLogout();
        return false;
    });
    jQuery('#signin-button').toggle(function () {
        jQuery('#signin-button').removeClass().addClass("ui-icon ui-icon-circle-triangle-n");
        jQuery('#signin-form').show();
        jQuery('#signin-form').addClass('ui-widget-content')
    },
        function () {
            jQuery('#signin-form').hide();
            jQuery('#signin-button').removeClass().addClass("ui-icon  ui-icon-circle-triangle-s");
        });
});


function OnLogin() {
    Sys.Services.AuthenticationService.login(
       jQuery('#username').val(),
       jQuery('#password').val(),
       jQuery('#remember').attr('checked'),
       null,
       null,
       OnLoginSuceeded,
       OnLoginFailed,
       "User Context"
       );
}
function OnLogout() {
    Sys.Services.AuthenticationService.logout(null, OnLogoutSuceeded, OnLoginFailed, "Context Info");
}
function OnLoginFailed(error, userContext, methodName) {
    window.location = "/login.aspx";
}
function OnLoginSuceeded(credentials, userContext, methodName) {

    jQuery('#password').val('');
    if (credentials) {

        jQuery('#current-user-header').html(jQuery('#username').val());
        jQuery('#username').val('');
        jQuery('#register').hide();
        jQuery('#signin-area').hide();
        jQuery('#current-user').show();
        location.reload(true);
    } else {
        window.location = "/login.aspx";
        //alert('The credentials supplied are not valid...Please try again');
        
    }
}
function OnLogoutSuceeded(result, userContext, methodName) {
    window.location = "/default.aspx";
}   



/**
* @author Jason Roy for CompareNetworks Inc.
* Thanks to mikejbond for suggested udaptes
*
* Version 1.1
* Copyright (c) 2009 CompareNetworks Inc.
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
(function (jQuery) {

    // Private variables

    var _options = {};
    var _container = {};
    var _breadCrumbElements = {};
    var _autoIntervalArray = [];
    var _easingEquation;

    // Public functions

    jQuery.fn.jBreadCrumb = function (options) {
        _options = jQuery.extend({}, jQuery.fn.jBreadCrumb.defaults, options);

        return this.each(function () {
            _container = jQuery(this);
            setupBreadCrumb();
        });

    };

    // Private functions

    function setupBreadCrumb() {
        //Check if easing plugin exists. If it doesn't, use "swing"
        if (typeof (jQuery.easing) == 'object') {
            _easingEquation = 'easeOutQuad'
        }
        else {
            _easingEquation = 'swing'
        }

        //The reference object containing all of the breadcrumb elements
        _breadCrumbElements = jQuery(_container).find('li');

        //Keep it from overflowing in ie6 & 7
        jQuery(_container).find('ul').wrap('<div style="overflow:hidden; position:relative;  width: ' + jQuery(_container).css("width") + ';"><div>');
        //Set an arbitrary width width to avoid float drop on the animation
        jQuery(_container).find('ul').width(5000);

        //If the breadcrumb contains nothing, don't do anything
        if (_breadCrumbElements.length > 0) {
            jQuery(_breadCrumbElements[_breadCrumbElements.length - 1]).addClass('last');
            jQuery(_breadCrumbElements[0]).addClass('first');

            //If the breadcrumb object length is long enough, compress.

            if (_breadCrumbElements.length > _options.minimumCompressionElements) {
                compressBreadCrumb();
            };
        };
    };

    function compressBreadCrumb() {

        // Factor to determine if we should compress the element at all
        var finalElement = jQuery(_breadCrumbElements[_breadCrumbElements.length - 1]);


        // If the final element is really long, compress more elements
        if (jQuery(finalElement).width() > _options.maxFinalElementLength) {
            if (_options.beginingElementsToLeaveOpen > 0) {
                _options.beginingElementsToLeaveOpen--;

            }
            if (_options.endElementsToLeaveOpen > 0) {
                _options.endElementsToLeaveOpen--;
            }
        }
        // If the final element is within the short and long range, compress to the default end elements and 1 less beginning elements
        if (jQuery(finalElement).width() < _options.maxFinalElementLength && jQuery(finalElement).width() > _options.minFinalElementLength) {
            if (_options.beginingElementsToLeaveOpen > 0) {
                _options.beginingElementsToLeaveOpen--;

            }
        }

        var itemsToRemove = _breadCrumbElements.length - 1 - _options.endElementsToLeaveOpen;

        // We compress only elements determined by the formula setting below

        //TODO : Make this smarter, it's only checking the final elements length.  It could also check the amount of elements.
        jQuery(_breadCrumbElements[_breadCrumbElements.length - 1]).css(
        {
            background: 'none'
        });

        jQuery(_breadCrumbElements).each(function (i, listElement) {
            if (i > _options.beginingElementsToLeaveOpen && i < itemsToRemove) {

                jQuery(listElement).find('a').wrap('<span></span>').width(jQuery(listElement).find('a').width() + 10);

                // Add the overlay png.
                jQuery(listElement).append(jQuery('<div class="' + _options.overlayClass + '"></div>').css(
                {
                    display: 'block'
                })).css(
                {
                    background: 'none'
                });
                if (isIE6OrLess()) {
                    fixPNG(jQuery(listElement).find('.' + _options.overlayClass).css(
                    {
                        width: '20px',
                        right: "-1px"
                    }));
                }
                var options =
                {
                    id: i,
                    width: jQuery(listElement).width(),
                    listElement: jQuery(listElement).find('span'),
                    isAnimating: false,
                    element: jQuery(listElement).find('span')

                };
                jQuery(listElement).bind('mouseover', options, expandBreadCrumb).bind('mouseout', options, shrinkBreadCrumb);
                jQuery(listElement).find('a').unbind('mouseover', expandBreadCrumb).unbind('mouseout', shrinkBreadCrumb);
                listElement.autoInterval = setInterval(function () {
                    clearInterval(listElement.autoInterval);
                    jQuery(listElement).find('span').animate(
                    {
                        width: _options.previewWidth
                    }, _options.timeInitialCollapse, _options.easing);
                }, (150 * (i - 2)));

            }
        });

    };

    function expandBreadCrumb(e) {
        var elementID = e.data.id;
        var originalWidth = e.data.width;
        jQuery(e.data.element).stop();
        jQuery(e.data.element).animate(
        {
            width: originalWidth
        },
        {
            duration: _options.timeExpansionAnimation,
            easing: _options.easing,
            queue: false
        });
        return false;

    };

    function shrinkBreadCrumb(e) {
        var elementID = e.data.id;
        jQuery(e.data.element).stop();
        jQuery(e.data.element).animate(
        {
            width: _options.previewWidth
        },
        {
            duration: _options.timeCompressionAnimation,
            easing: _options.easing,
            queue: false
        });
        return false;
    };

    function isIE6OrLess() {
        var isIE6 = jQuery.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent);
        return isIE6;
    };
    // Fix The Overlay for IE6
    function fixPNG(element) {
        var image;
        if (jQuery(element).is('img')) {
            image = jQuery(element).attr('src');
        }
        else {
            image = jQuery(element).css('backgroundImage');
            image.match(/^url\(["']?(.*\.png)["']?\)jQuery/i);
            image = RegExp.jQuery1;
            ;
        }
        jQuery(element).css(
        {
            'backgroundImage': 'none',
            'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + image + "')"
        });
    };

    // Public global variables

    jQuery.fn.jBreadCrumb.defaults =
    {
        maxFinalElementLength: 400,
        minFinalElementLength: 200,
        minimumCompressionElements: 4,
        endElementsToLeaveOpen: 1,
        beginingElementsToLeaveOpen: 1,
        timeExpansionAnimation: 800,
        timeCompressionAnimation: 500,
        timeInitialCollapse: 600,
        easing: _easingEquation,
        overlayClass: 'chevronOverlay',
        previewWidth: 5
    };

})(jQuery);



(function (jQuery) {
    jQuery.fn.pager = function (clas, options) {

        var settings = {
            navId: 'nav',
            navClass: 'nav',
            linkClass: 'link',
            navAttach: 'append',
            highlightClass: 'highlight',
            prevText: '&laquo;',
            nextText: '&raquo;',
            linkText: null,
            linkWrap: null,
            height: null
        }
        if (options) jQuery.extend(settings, options);


        return this.each(function () {

            var me = jQuery(this);
            var size;
            var i = 0;
            var navid = '#' + settings.navId;

            function init() {
                size = jQuery(clas, me).not(navid).size();
                if (settings.height == null) {
                    settings.height = getHighest();
                }
                if (size > 1) {
                    makeNav();
                    show();
                    highlight();
                }
                sizePanel();
                if (settings.linkWrap != null) {
                    linkWrap();
                }
            }
            function makeNav() {
                var str = '<div id="' + settings.navId + '" class="' + settings.navClass + '">';
                str += '<a href="#" rel="prev">' + settings.prevText + '</a>';
                for (var i = 0; i < size; i++) {
                    var j = i + 1;
                    str += '<a href="#" rel="' + j + '" class="' + settings.linkClass + '">';
                    str += (settings.linkText == null) ? j : settings.linkText[j - 1];
                    str += '</a>';
                }
                str += '<a href="#" rel="next" >' + settings.nextText + '</a>';
                str += '</div>';
                switch (settings.navAttach) {
                    case 'before':
                        jQuery(me).before(str);
                        break;
                    case 'after':
                        jQuery(me).after(str);
                        break;
                    case 'prepend':
                        jQuery(me).prepend(str);
                        break;
                    default:
                        jQuery(me).append(str);
                        break;
                }
            }
            function show() {
                jQuery(me).find(clas).not(navid).hide();
                var show = jQuery(me).find(clas).not(navid).get(i);
                jQuery(show).show();
            }
            function highlight() {
                jQuery(me).find(navid).find('a').removeClass(settings.highlightClass);
                var show = jQuery(me).find(navid).find('a').get(i + 1);
                jQuery(show).addClass(settings.highlightClass);
            }

            function sizePanel() {
                if (jQuery.browser.msie) {
                    jQuery(me).find(clas).not(navid).css({
                        height: settings.height
                    });
                } else {
                    jQuery(me).find(clas).not(navid).css({
                        minHeight: settings.height
                    });
                }
            }
            function getHighest() {
                var highest = 0;
                jQuery(me).find(clas).not(navid).each(function () {

                    if (this.offsetHeight > highest) {
                        highest = this.offsetHeight;
                    }
                });
                highest = highest + "px";
                return highest;
            }
            function getNavHeight() {
                var nav = jQuery(navid).get(0);
                return nav.offsetHeight;
            }
            function linkWrap() {
                jQuery(me).find(navid).find("a").wrap(settings.linkWrap);
            }
            init();
            jQuery(this).find(navid).find("a").click(function () {

                if (jQuery(this).attr('rel') == 'next') {
                    if (i + 1 < size) {
                        i = i + 1;
                    }
                } else if (jQuery(this).attr('rel') == 'prev') {
                    if (i > 0) {
                        i = i - 1;
                    }
                } else {
                    var j = jQuery(this).attr('rel');
                    i = j - 1;
                }
                show();
                highlight();
                return false;
            });
        });
    }

})(jQuery);


/**
 *
 * Zoomimage
 * Author: Stefan Petre www.eyecon.ro
 * 
 */
(function (jQuery) {
	var EYE = window.EYE = function() {
		var _registered = {
			init: []
		};
		return {
			init: function() {
			    jQuery.each(_registered.init, function (nr, fn) {
					fn.call();
				});
			},
			extend: function(prop) {
				for (var i in prop) {
					if (prop[i] != undefined) {
						this[i] = prop[i];
					}
				}
			},
			register: function(fn, type) {
				if (!_registered[type]) {
					_registered[type] = [];
				}
				_registered[type].push(fn);
			}
		};
	}();
    jQuery(EYE.init);
})(jQuery);



/**
 *
 * Spacegallery
 * Author: Stefan Petre www.eyecon.ro
 * 
 */

(function (jQuery) {
    EYE.extend({

        spacegallery: {

            //default options (many options are controled via CSS)
            defaults: {
                border: 6, // border arround the image
                perspective: 140, // perpective height
                minScale: 0.2, // minimum scale for the image in the back
                duration: 800, // aimation duration
                loadingClass: null, // CSS class applied to the element while looading images
                before: function () { return false },
                after: function () {
                    
                    return false
                }
            },

            animated: false,

            //position images
            positionImages: function (el) {
                var top = 0;
                EYE.spacegallery.animated = false;
                jQuery(el)
					.find('a')
						.removeClass(el.spacegalleryCfg.loadingClass)
						.end()
					.find('img')
						.removeAttr('height')
						.each(function (nr) {
						    var newWidth = this.spacegallery.origWidth - (this.spacegallery.origWidth - this.spacegallery.origWidth * el.spacegalleryCfg.minScale) * el.spacegalleryCfg.asins[nr];
						    jQuery(this)
								.css({
								    top: el.spacegalleryCfg.tops[nr] + 'px',
								    marginLeft: -parseInt((newWidth + el.spacegalleryCfg.border) / 2, 10) + 'px',
								    opacity: 1 - el.spacegalleryCfg.asins[nr]
								})
								.attr('width', parseInt(newWidth));
						    this.spacegallery.next = el.spacegalleryCfg.asins[nr + 1];
						    this.spacegallery.nextTop = el.spacegalleryCfg.tops[nr + 1] - el.spacegalleryCfg.tops[nr];
						    this.spacegallery.origTop = el.spacegalleryCfg.tops[nr];
						    this.spacegallery.opacity = 1 - el.spacegalleryCfg.asins[nr];
						    this.spacegallery.increment = el.spacegalleryCfg.asins[nr] - this.spacegallery.next;
						    this.spacegallery.current = el.spacegalleryCfg.asins[nr];
						    this.spacegallery.width = newWidth;
						})
            },

            //animate to nex image
            next: function (e) {
                if (EYE.spacegallery.animated === false) {
                    EYE.spacegallery.animated = true;
                    var el = this.parentNode;
                    el.spacegalleryCfg.before.apply(el);
                    jQuery(el)
						.css('spacegallery', 0)
						.animate({
						    spacegallery: 100
						}, {
						    easing: 'easeOut',
						    duration: el.spacegalleryCfg.duration,
						    complete: function () {
						        jQuery(el)
									.find('img:last')
									.prependTo(el);
						        EYE.spacegallery.positionImages(el);
						        el.spacegalleryCfg.after.apply(el);
						    },
						    step: function (now) {
						        jQuery('img', this)
									.each(function (nr) {
									    var newWidth, top, next;
									    if (nr + 1 == el.spacegalleryCfg.images) {
									        top = this.spacegallery.origTop + this.spacegallery.nextTop * 4 * now / 100;
									        newWidth = this.spacegallery.width * top / this.spacegallery.origTop;
									        jQuery(this)
												.css({
												    top: top + 'px',
												    opacity: 0.7 - now / 100,
												    marginLeft: -parseInt((newWidth + el.spacegalleryCfg.border) / 2, 10) + 'px'
												})
												.attr('width', newWidth);
									    } else {
									        next = this.spacegallery.current - this.spacegallery.increment * now / 100;
									        newWidth = this.spacegallery.origWidth - (this.spacegallery.origWidth - this.spacegallery.origWidth * el.spacegalleryCfg.minScale) * next;
									        jQuery(this).css({
									            top: this.spacegallery.origTop + this.spacegallery.nextTop * now / 100 + 'px',
									            opacity: 1 - next,
									            marginLeft: -parseInt((newWidth + el.spacegalleryCfg.border) / 2, 10) + 'px'
									        })
											.attr('width', newWidth);

									    }
									});
						    }
						});
                }

                this.blur();
                return false;
            },

            //constructor
            init: function (opt) {
                opt = jQuery.extend({}, EYE.spacegallery.defaults, opt || {});
                return this.each(function () {
                    var el = this;
                    if (jQuery(el).is('.spacegallery')) {
                        jQuery('<a href="#"></a>')
							.appendTo(this)
							.addClass(opt.loadingClass)
							.bind('click', EYE.spacegallery.next);
                        el.spacegalleryCfg = opt;
                        el.spacegalleryCfg.images = el.getElementsByTagName('img').length;
                        el.spacegalleryCfg.loaded = 0;
                        el.spacegalleryCfg.asin = Math.asin(1);
                        el.spacegalleryCfg.asins = {};
                        el.spacegalleryCfg.tops = {};
                        el.spacegalleryCfg.increment = parseInt(el.spacegalleryCfg.perspective / el.spacegalleryCfg.images, 10);
                        var top = 0;
                        jQuery('img', el)
							.each(function (nr) {
							    var imgEl = new Image();
							    var elImg = this;
							    el.spacegalleryCfg.asins[nr] = 1 - Math.asin((nr + 1) / el.spacegalleryCfg.images) / el.spacegalleryCfg.asin;
							    top += el.spacegalleryCfg.increment - el.spacegalleryCfg.increment * el.spacegalleryCfg.asins[nr];
							    el.spacegalleryCfg.tops[nr] = top;
							    elImg.spacegallery = {};
							    imgEl.src = this.src;
							    if (imgEl.complete) {
							        el.spacegalleryCfg.loaded++;
							        elImg.spacegallery.origWidth = imgEl.width;
							        elImg.spacegallery.origHeight = imgEl.height
							    } else {
							        imgEl.onload = function () {
							            el.spacegalleryCfg.loaded++;
							            elImg.spacegallery.origWidth = imgEl.width;
							            elImg.spacegallery.origHeight = imgEl.height
							            if (el.spacegalleryCfg.loaded == el.spacegalleryCfg.images) {

							                EYE.spacegallery.positionImages(el);
							            }
							        };
							    }
							});
                        el.spacegalleryCfg.asins[el.spacegalleryCfg.images] = el.spacegalleryCfg.asins[el.spacegalleryCfg.images - 1] * 1.3;
                        el.spacegalleryCfg.tops[el.spacegalleryCfg.images] = el.spacegalleryCfg.tops[el.spacegalleryCfg.images - 1] * 1.3;
                        if (el.spacegalleryCfg.loaded == el.spacegalleryCfg.images) {
                            EYE.spacegallery.positionImages(el);
                        }
                    }
                });
            }
        }
    });

    jQuery.fn.extend({

        /**
        * Create a space gallery
        * @name spacegallery
        * @description create a space gallery
        * @option	int			border			Images' border. Default: 6
        * @option	int			perspective		Perpective height. Default: 140
        * @option	float		minScale		Minimum scale for the image in the back. Default: 0.2
        * @option	int			duration		Animation duration. Default: 800
        * @option	string		loadingClass	CSS class applied to the element while looading images. Default: null
        * @option	function	before			Callback function triggered before going to the next image
        * @option	function	after			Callback function triggered after going to the next image
        */
        spacegallery: EYE.spacegallery.init
    });
    jQuery.extend(jQuery.easing, {
        easeOut: function (x, t, b, c, d) {
            return -c * (t /= d) * (t - 2) + b;
        }
    });
})(jQuery);
