/*************************************************************
************ JavaScript Document *****************************
*************************************************************/

/*************************************************************
************ jQuery ******************************************
*************************************************************/


/*********** DOucument ready ********************************/
$(document).ready(function() 
	{			

$('#channels li p strong a').hover(function() {
		if ($.browser.msie) { $(this).parent().parent().parent().find('div').show(); } 
		$(this).parent().parent().parent().find('div').fadeIn(300);
	}, function() {
		if ($.browser.msie) { $(this).parent().parent().parent().find('div').hide(); } 
		$(this).parent().parent().parent().find('div').fadeOut(300);
});

/*********** Spela, pausa m.m. ******************************/
		
$('#remote').toggle(function() {
	$('#media_content').cycle('pause');
	$(this).attr({ src: "/img/play.png", title: "spela bildspelet"});

	}, function() {

	$('#media_content').cycle('resume', true);
	$(this).attr({src: "/img/pause.png", title: "pausa bildspelet"});
});
		
/*********** Bildspel med rubrik och text *******************/
		
$('#media_content') 
.after('<div id="nav">') 
.cycle({ 
fx:     'fade', 
speed:  '1000', 
timeout: 5000, 
pager:  '#nav',
pause: 	true,
//next:   '#next', 
//before:  onBefore, 
//after:   onAfter,
//slideExpr: 'li'
cleartype:  true,
cleartypeNoBg:  true
//pagerAnchorBuilder: function(idx, slide) {
//	// return selector string for existing anchor
// return '#brands li a:eq(' + idx + ') ';
//}

});

$('#media_content.brands') 
.after('<div id="nav">') 
.cycle({ 
fx:     'fade', 
speed:  '1000', 
timeout: 0, 
pager:  '#nav',
pause: 	true,
//next:   '#next', 
//before:  onBefore, 
//after:   onAfter,
//slideExpr: 'li'
cleartype:  true,
cleartypeNoBg:  true,
pagerAnchorBuilder: function(idx, slide) {
	// return selector string for existing anchor
 return '#top_menu a:eq(' + idx + ') ';
}
});

//$("#top_menu a").click(function(){
//	  $(this).toggleClass("active");
//	});


/*********** Sprites startsida *******************/

$(".sprites li").hover(function() { //On hover...

	var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

	//Set a background image(thumbOver) on the <a> tag - Set position to bottom
	$(this).find("a").css({'background' : '#f0f0f0 url(' + thumbOver + ') no-repeat center bottom'});

	//Animate the image to 0 opacity (fade it out)
	$(this).find("img").stop().fadeTo('normal', 0 , function() {
		$(this).hide() //Hide the image after fade
	});
} , function() { //on hover out...
	//Fade the image to full opacity
$(this).find("img").stop().fadeTo('normal', 1).show();
});

/*********** Animerad nav ************************/

	$("#nav").animate({bottom: "+=200"}, 2000)
		  //return false;
		  
		$("#nav a").hover(function() {
			  $(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
			}, function() {
			  $(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
			});

/*********** Accordion **************************/
	
	$('#accordion').accordion({
		header: 'h3',
		navigation: false,
		active: '.selected',
		autoheight: false,
		clearStyle: true,
		collapsible: true,
		alwaysOpen: false,
		animated: 'slide'
	});

/*********** Doucument ready slut****************************/
	}
);
/*********** Doucument ready slut ***************************/

/*************************************************************
************ Andra JS ****************************************
*************************************************************/

/*********** Searcbox ***************************************/
$(function() {
	swapValues = [];
	$(".swap_value").each(function(i){
		swapValues[i] = $(this).val();
		$(this).focus(function(){
			if ($(this).val() == swapValues[i]) {
				$(this).val("");
			}
		}).blur(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(swapValues[i]);
			}
		});
	});
});

/*********** Externa länkar *********************************/
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;

function toggle_visibility(part) 
{
	var e = document.getElementById(part);
	if(e.style.display == 'none'){
		e.style.display = 'inline';}
	else{
		e.style.display = 'none';}
}

/*********** Öppna/stäng varukorg ****************************/
function ShowHideCart() {
    if ($('#cart_info').is(':hidden')) {
        $('#cart_info').slideDown('medium');
        $('#cart_trigger').attr({ innerHTML: "St&auml;ng varukorg", title: "St&auml;ng varukorg" });
    }
    else {
		$('#cart_info').slideUp('medium');
        $('#cart_trigger').attr({ innerHTML: "Visa varukorg", title: "Visa varukorg" });
    }
}

/*********** Popup *******************************************/
function ShowFancybox(headline, text) {
    $h1 = $('<h1/>').append(headline);
    $p = $('<p/>').append(text);
    $cont = $('<div/>').append($h1).append($p);
    $('#fancybox_content').empty().css('display', 'block').append($cont);

    $("#fancybox_trigger").fancybox({
        'hideOnContentClick': false,
        onClosed: function() {
            $('#fancybox_content').hide(); 
        }
    }).trigger('click');
}

function ShowLoader() {
    // visa ajax loader
}

function HideLoader() {
    // dölj ajax loader
}

function CreateULErrorList(ulclass, liclass, errors) {
    var list = $('<ul/>').addClass(ulclass);

    $.each(errors, function() {
        list.append($('<li/>').addClass(liclass).append(this.toString()));
    });

    return list;
}

function CreateULList(ulclass, liclass, listOfStringItems) {
    var list = $('<ul/>').addClass(ulclass);

    $.each(listOfStringItems, function() {
        list.append($('<li/>').addClass(liclass).append(this.toString()));
    });

    return list;
}

function HideCartDelayed() {
    setTimeout('ShowHideCart();', 3000);
}
