﻿// plugins
/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
				encodeURIComponent(key), '=',
				options.raw ? value : encodeURIComponent(value),
				options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
				options.path ? '; path=' + options.path : '',
				options.domain ? '; domain=' + options.domain : '',
				options.secure ? '; secure' : ''
			].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};


(function (d) { var c = false, g = null; d.tinysort = { id: "TinySort", version: "1.1.1", copyright: "Copyright (c) 2008-2011 Ron Valstar", uri: "http://tinysort.sjeiti.com/", licenced: { MIT: "http://www.opensource.org/licenses/mit-license.php", GPL: "http://www.gnu.org/licenses/gpl.html" }, defaults: { order: "asc", attr: g, data: g, useVal: c, place: "start", returns: c, cases: c, forceStrings: c, sortFunction: g} }; d.fn.extend({ tinysort: function (l, f) { if (l && typeof (l) != "string") { f = l; l = g } var m = d.extend({}, d.tinysort.defaults, f), v = parseFloat, s, A = {}, o = !(!l || l == ""), r = !(m.attr === g || m.attr == ""), w = m.data !== g, h = o && l[0] == ":", j = h ? this.filter(l) : this, q = m.sortFunction; if (!q) { q = m.order == "rand" ? function () { return Math.random() < 0.5 ? 1 : -1 } : function (C, p) { var i = !m.cases ? b(C.s) : C.s, D = !m.cases ? b(p.s) : p.s; if (!m.forceStrings && e(C.s) && e(p.s)) { i = v(C.s); D = v(p.s) } return (m.order == "asc" ? 1 : -1) * (i < D ? -1 : (i > D ? 1 : 0)) } } this.each(function (C, E) { var D = d(E), G = o ? (h ? j.filter(this) : D.find(l)) : D, F = w ? G.data(m.data) : (r ? G.attr(m.attr) : (m.useVal ? G.val() : G.text())), p = D.parent(); if (!A[p]) { A[p] = { s: [], n: []} } if (G.length > 0) { A[p].s.push({ s: F, e: D, n: C }) } else { A[p].n.push({ e: D, n: C }) } }); for (s in A) { A[s].s.sort(q) } var k = []; for (s in A) { var x = A[s], z = [], B = d(this).length; switch (m.place) { case "first": d.each(x.s, function (p, C) { B = Math.min(B, C.n) }); break; case "org": d.each(x.s, function (p, C) { z.push(C.n) }); break; case "end": B = x.n.length; break; default: B = 0 } var u = [0, 0]; for (var y = 0; y < d(this).length; y++) { var n = y >= B && y < B + x.s.length; if (a(z, y)) { n = true } var t = (n ? x.s : x.n)[u[n ? 0 : 1]].e; t.parent().append(t); if (n || !m.returns) { k.push(t.get(0)) } u[n ? 0 : 1]++ } } return this.pushStack(k) } }); function b(f) { return f && f.toLowerCase ? f.toLowerCase() : f } function e(h) { var f = /^\s*?[\+-]?(\d*\.?\d*?)\s*?$/.exec(h); return f && f.length > 0 ? f[1] : c } function a(h, i) { var f = c; d.each(h, function (k, j) { if (!f) { f = j == i } }); return f } d.fn.TinySort = d.fn.Tinysort = d.fn.tsort = d.fn.tinysort })(jQuery);

// End plugins



var mouseX, mouseY = 0;

jQuery(document).ready(function()
{
	
	
        jQuery().mousemove(function(e){
          mouseX = e.pageX;
          mouseY = e.pageY;
       });
       
        loadEffects();
        
        jQuery("input[type='text'], input[type='password']").addClass("text_input");
        
        jQuery(window).resize(function(){
            jQuery("#popin_coverDiv").height(jQuery(window).height());
	        jQuery("#popin_coverDiv").width(jQuery(window).width());
	        jQuery("#popin_coverDiv").height(jQuery(document).height());
	        jQuery("#popin_coverDiv").width(jQuery(document).width());
        });

        jQuery("input[idjQuery=fileProfilePhoto]").change(function()
        {

            jQuery("[idjQuery=btnUpload]").click();
            jQuery("#uploadFileForm").fadeOut(300);
        });
		


			jQuery("#st1").click(function () {
			jQuery("#tCon1").slideDown("slow");
		
	});
	
		jQuery("#st2").click(function () {
			jQuery("#tCon2").slideToggle("slow");
		
	});
		
		

	

});


function loadEffects()
{
            jQuery(".ui-fade-rollover").each(function(){
	            if(jQuery(this).attr("effect_loaded") == "true") return;
	            jQuery(this).attr("effect_loaded", "true"); 
               
			    //if(jQuery(this).attr("alt") != null && curNavSection != "" && jQuery(this).attr("alt").indexOf(curNavSection) != -1)
                //{
                    //jQuery(this).attr("src", jQuery(this).attr("src").replace("_off", "_over"));
               // }
	            var wrapper = "<div style='display: block; height: auto; width: auto; background-repeat: no-repeat; background-image: url(" + jQuery(this).attr("src").replace("_off", "_over") + ")'></div>";
	            if(jQuery(this).parent().get(0).tagName == "A")
	            {
		            jQuery(this).parent().wrap(wrapper);
	            }
	            else
	            {
		            jQuery(this).wrap(wrapper);
	            }
	            
	            jQuery(this).bind("mouseenter", function(e){
	                jQuery(this).stop().animate({opacity: 0}, 300);
	            });
	            jQuery(this).bind("mouseleave", function(e){
	                jQuery(this).stop().animate({opacity: 1}, 300);
	            });


           
            
            
            });
            
                jQuery('img.swapImage').hover(function() {
                    jQuery(this).attr("src", jQuery(this).attr("src").replace("_off", "_over"));
					if(jQuery(this).attr("oSrc") != null)
					{
						jQuery(this).attr("src", jQuery(this).attr("oSrc").replace("_off", "_over"));
					}
                },
                
                function() {
                    jQuery(this).attr("src", jQuery(this).attr("src").replace("_over", "_off"));
					if(jQuery(this).attr("oSrc") != null)
					{
						jQuery(this).attr("src", jQuery(this).attr("oSrc").replace("_over", "_off"));
					}
                });
            

            
}


function randomListWithCookie(cookieName, targetElement) {

    // Set or use a cookie with a list of 100 randomly orderd ints.
    // Match index of targeted element and use the faux lookup list to get a random "sort id" and attach as the id on the element
    // Then use sort plugin to sort by the id

    var collection = new Array();

    if (!$.cookie(cookieName)) {
        for (i = 0; i < 100; i++) {
            collection.push(i);
        }
        collection.sort(randOrd);

        $.cookie(cookieName, collection, { expires: 7 });
    }

    // Get cookie and create real array again
    var cPgEtailerSort = jQuery.makeArray($.cookie(cookieName).split(","));
    for (var i = 0; i < cPgEtailerSort.length; i++) { cPgEtailerSort[i] = +cPgEtailerSort[i]; }

    function randOrd(a, b) {
        return (0.5 - Math.random());
    }


    $(targetElement).each(function (i) {
        //alert(collection[i]);
        $(this).attr('id', 'sortOrder' + cPgEtailerSort[i]);
    });

    $(targetElement).tsort({ attr: 'id' });
}
