﻿
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


$(document).ready(function() {


    
    checkCookie();
    $('input[type="text"]').focus(cleanText);
	$('input[type="text"]').blur(cleanText);
    // Initiate Tabswitching
    $("div.designBodyTabGridTabs").children("a").click(function () {
        if (!$(this).hasClass("selected")) {
            $(this).addClass("selected").siblings("a").removeClass("selected")
            $(this).parent().parent().children("div.designBodyTabGridContent").slideUp(300);
            $("#"+$(this).attr("id")+"Content").slideDown(300)
        }
    });
    
    $(".inputfield")
			.focus(function () 
			{
					$(this).removeClass("inactive");
					if ($(this).val()==$(this).attr("title"))
							$(this).val("");
			})
			.blur(function () 
			{
					if ($(this).val()=="")
					{
							$(this).addClass("inactive");
							$(this).val($(this).attr('title'));
					}
			});
    
});

function popupAd() {

    $('body div:first').append(
				'<div class="lightbox-container">'+
			    	'<div class="close-btn"></div>' +
					'<div class="lightbox"  style="cursor: pointer; z-index: 999;" onclick="javascript:window.open(\'http://raimat.se/Vinprovning_online/teaser.aspx\', \'_self\')">' + 
						'<p class="spacing">' +
                                '<h1>Exklusivt på raimat.se!</h1>'+
                                '<h2>Interaktiv vinprovning med Ulf Sjödin, Master of Wine</h2>'+
                                '<h2>torsdagen den 15 oktober kl.20:00</h2>'+
	                            '<p class="spacing">Vi kommer att prova följande tre viner:Raimat Abadia Crianza, Raimat Abadia Blanc de Blancs, Raimat Cabernet Sauvignon' + '</p><br />' +
	                            '<p class="spacing">Missa inte detta!</p>'+
	                     '</p><br />' +
				'<p class="spacing"><a href="/Vinprovning_online/teaser.aspx" class="submitbutton2"><span>läs mer</span></a></p>' +
		 '</div>' + 
	 '</div>'
			 );

    $('div.lightbox').mouseover(function() {
    $('div.lightbox').css('background', '#191919');
     });

        $('div.lightbox').mouseout(function() {
            $('div.lightbox').css('background', '#050505');
        });
			 
		$("#lightbox_message").hide();
		$("#lightbox_message").fadeIn(500);

    $('.close-btn').click(function() {
    $(".lightbox-container").fadeOut(500);
    });
}

function checkCookie()
	{
        
    	/*if($.cookie('popup') != '1'){
    	
    	    popupAd();
    	    $.cookie('popup', 1, {expires: 1});
    	    
    	} 
    		*/
    	
    	//Om cookie inte finns (popupAd())
    	
    	//Sätt cookie()
    	
	  
	
		//var koll = $.cookie("koll"); // get cookie
		
		//if(koll !=null && koll == 1)
		//{
		//	$("#lightbox_message").remove();
		//}

	}

function showMessage(message)
{
	$(document).ready(function() {
		$(document.body).append(
			'<div class="lightbox_wrapper" id="lightbox_message">' + 
				'<div class="lightbox_background"></div>' + 
					'<div class="lightbox">' + 
						'<p class="spacing">' + 
							message + 
						'</p><br />' + 
						'<p class="spacing"><input type="button" onclick="$(\'#lightbox_message\').fadeOut(500);" class="submitbutton" value="Stäng" /></p>' + 
				 '</div>' + 
			 '</div>'
			 );
		$("#lightbox_message").hide();
		$("#lightbox_message").fadeIn(500);
	});
}


function cleanText(event) {

    var element = this;

    //alert();
    
    if ($(element).attr("value") == $(element).attr("title")) {

        $(element).attr("value", "");

    }

    else if ($(element).attr("value") == "" && event.type != "click") {

        $(element).attr("value", $(element).attr("title"));

    }

}

